Date: Tue, 8 May 2012 15:57:44 +0000
Reply-To: "Zdeb, Michael S" <mzdeb@ALBANY.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Zdeb, Michael S" <mzdeb@ALBANY.EDU>
Subject: Re: Deleting Variables
In-Reply-To: <201205081551.q48Eb0CS031043@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
hi ... you said ... "so my data set should look like this ..."
ID varA VarB
1 1 .
1 2 1
1 3 0
did you try ...
data x;
input id vara varb;
datalines;
1 1 .
1 2 1
1 3 0
2 1 .
2 2 0
2 3 0
;
data want (drop=info);
length info $100;
do until (last.id);
set x (in=one) x;
by id;
if one then info = catx('*',info,catt(vara,varb));
if ^one and ^(find(info,'20') and find(info,'30')) then output;
end;
run;
proc print data=want noobs;
run;
results ...
id vara varb
1 1 .
1 2 1
1 3 0
looks just like your data set, so tell us (me, I'm really interested) "what's not working"
Mike Zdeb
U@Albany School of Public Health
One University Place (Room 119)
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
________________________________________
From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] on behalf of Randy [randistan69@HOTMAIL.COM]
Sent: Tuesday, May 08, 2012 11:51 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Deleting Variables
Dear All:
None of these codes work. :-(
Randy
On Tue, 8 May 2012 15:06:52 +0000, Zdeb, Michael S <mzdeb@ALBANY.EDU>
wrote:
>hi ... another idea (it's really "deleting observations" not "deleting
variables" ... yes/no?)
>
>data x;
>input id vara varb;
>datalines;
>1 1 .
>1 2 1
>1 3 0
>2 1 .
>2 2 0
>2 3 0
>;
>
>data want (drop=info);
>length info $100;
>do until (last.id);
> set x (in=one) x;
> by id;
> if one then info = catx('*',info,catt(vara,varb));
> if ^one and ^(find(info,'20') and find(info,'30')) then output;
>end;
>run;
>
>Mike Zdeb
>U@Albany School of Public Health
>One University Place (Room 119)
>Rensselaer, New York 12144-3456
>P/518-402-6479 F/630-604-1475
>
>________________________________________
>From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] on behalf of Randy
[randistan69@HOTMAIL.COM]
>Sent: Tuesday, May 08, 2012 10:13 AM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Deleting Variables
>
>My dataset is as follows:
>
>ID varA VarB
>1 1 .
>1 2 1
>1 3 0
>2 1 .
>2 2 0
>2 3 0
>
>I want to delete each ID where VarA = 2 and VarB =0 and VarA = 3 and VarB
>= 0. Note that for all VarA = 1 VarB = . .
>
>so my data set should look like this :
>
>ID varA VarB
>1 1 .
>1 2 1
>1 3 0
>
>I wrote the following:
>
>data want ; set have ;
>if (VarA = 1 and VarB = .) and
>(VarA = 2 and VarB = 0) and
>(VarA = 3 and VarB = 0) then delete ;
>run;
>
>Somehow, I am not getting the logic correct. Please help.
> Randy
|