Date: Tue, 6 Oct 2009 12:27:20 -0700
Reply-To: "Richard A. DeVenezia" <rdevenezia@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <rdevenezia@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: I want to drop a specific variable with a specific value
Content-Type: text/plain; charset=ISO-8859-1
On Oct 6, 12:36 pm, troman....@GMAIL.COM (Theresa Roman) wrote:
> Hello,
>
> Any suggestions will be greatly appreciated.
>
> Nature of the dataset: 13 variables UNIQUE ID, Q13-Q18 and Q13s-Q18s
>
> Goal: logic check.
>
> Possible values of Q12-Q18 are 1, 2, or 3.
> Q13s-Q18s are character variables
>
> Here is what i have so far:
>
> data check;
> set form1;
> If (Q13 in (2,3) and Q13s=' ') or (Q14 in (2,3) and Q14s=' ') or (Q15 in
> (2,3) and Q15s=' ') or (Q16 in (2,3) and Q16s=' ') or (Q17 in (2,3) and
> Q17s=' ') or (Q18 in (2,3) and Q18s=' ');
> run;
>
> so basically if q13 is 2 or 3, Q13s can't be left blank same idea with
> Q14-Q18.
>
> So I want data set "check' to have only those variables where this is the
> case.
> However, using the code above, I am getting all 12 variables again. So if at
> least for one question from Q13-Q18 this is true I get all the variables.
> Does that make sense?
Yes that does make sense.
>
> I don't want that. I only want the variables where Qi is in 2,3 and Qis is
> blank to show, nothing else. where i is 13 to 18.
>
> Any suggestions?
A single observation contains all variables of a dataset. There is no
way to specify 'this row has these columns, and that row has those
columns'
By rearranging the data (transposition), each index (13 to 18) can be
put on a different row. In that way an index can be excluded by _not_
having a row for it.
------------
data have;
array x(11:19);
array xs(11:19) $8;
do rowid = 1 to 100;
do i = lbound(x) to hbound(x);
x(i) = ceil (3*ranuni(1234));
if ranuni(1234) < 0.15 then
xs(i) = 'Somethin';
else
xs(i) = '';
end;
output;
end;
drop i;
run;
data want(keep=rowid index numvalue charvalue);
set have;
array x(11:19);
array xs(11:19);
do index = lbound(x) to hbound(x);
if x(index) in (2,3) and xs(index) = '' then do;
numvalue = x(index);
charvalue = xs(index);
OUTPUT;
end;
end;
run;
------------
--
Richard A. DeVenezia
http://www.devenezia.com