Date: Tue, 8 May 2012 15:06:52 +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: <201205081413.q484Yqc6031043@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
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