| Date: | Tue, 20 Dec 2011 14:18:42 -0500 |
| Reply-To: | "Bian, Haikuo" <HBian@FLQIO.SDPS.ORG> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Bian, Haikuo" <HBian@FLQIO.SDPS.ORG> |
| Subject: | Re: Need help in SAS code |
|
| In-Reply-To: | <10B2B6145FFC184E88E26DFB7C4DD82DF748AE4B@URMCMS4.urmc-sh.rochester.edu> |
| Content-Type: | text/plain; charset="us-ascii" |
2X DU Loop seems to do the job:
data TEST;
input primary_ID $ secondary_ID $ var $;
cards;
A1 B1 A
A1 B2 A
A1 B3 A
A2 B1 B
A2 B2 C
A3 B1 D
A3 B1 A
A3 B1 B
A4 B1 C
A4 B2 C
A5 B1 D
A5 B2 A
A5 B3 B
A6 B1 A
A6 B2 C
A6 B3 A
A7 B1 D
A7 B2 D
A7 B3 D
A8 B1 A
A8 B2 B
A8 B3 C
;
run;
data want (drop=_:) ;
length _cat $40.
_com $40.;
retain _com _cat;
do until (last.primary_ID);
set test;
by primary_ID;
if first.primary_id then call missing(_cat);
_cat=catx(' ',_cat,var);
end;
_com=strip(compress(_cat, 'AC'));
do until (last.primary_ID);
set test;
by primary_ID;
if not missing(_com) then output;
end;
run;
proc print;run;
Kindly Regards,
Haikuo
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Elumalai, Meena
Sent: Tuesday, December 20, 2011 1:35 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Need help in SAS code
Hello,
I have data set like below and want to remove the following from the dataset.
1) where all the values for var is only 'A' by primary_ID.
2) where all the values for var is only 'C' by primary_ID.
3) where all the values for var is either 'A' or 'C' by primary_ID.
In this sample, will delete primary_ID A1, A4 and A6.
data TEST;
input primary_ID$ secondary_ID$ var $;
cards;
A1 B1 A
A1 B2 A
A1 B3 A
A2 B1 B
A2 B2 C
A3 B1 D
A3 B1 A
A3 B1 B
A4 B1 C
A4 B2 C
A5 B1 D
A5 B2 A
A5 B3 B
A6 B1 A
A6 B2 C
A6 B3 A
A7 B1 D
A7 B2 D
A7 B3 D
A8 B1 A
A8 B2 B
A8 B3 C
run;
Thanks
Meena
-----------------------------------------
Email messages cannot be guaranteed to be secure or error-free as
transmitted information can be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The
Centers for Medicare & Medicaid Services therefore does not accept
liability for any error or omissions in the contents of this
message, which arise as a result of email transmission.
CONFIDENTIALITY NOTICE: This communication, including any
attachments, may contain confidential information and is intended
only for the individual or entity to which it is addressed. Any
review, dissemination, or copying of this communication by anyone
other than the intended recipient is strictly prohibited. If you
are not the intended recipient, please contact the sender by reply
email and delete and destroy all copies of the original message.
|