LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 20 Dec 2011 14:19:34 -0500
Reply-To:   Mike Jacobsen <nordath1@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Mike Jacobsen <nordath1@GMAIL.COM>
Subject:   Re: Need help in SAS code
Comments:   To: Jack Clark <jclark@hilltop.umbc.edu>
In-Reply-To:   <456B52C41B724C41B96561D7AD283E7D01F05593@mail.chpdm.umbc.edu>
Content-Type:   text/plain; charset=ISO-8859-1

you could also try this:

data test; set test; if var="A" then mark=1; else if var="C" then mark=1; run; proc summary data=test n; by primary_ID; var mark; output out=count n=n; run; proc sort data=test; by primary_ID; run; proc sort data=count; by primary_ID; run; data final; merge test count; by primary_ID; if _FREQ_=n then delete; drop _type_ _freq_ n mark; run; proc print; run;

On Tue, Dec 20, 2011 at 2:13 PM, Jack Clark <jclark@hilltop.umbc.edu> wrote:

> Meena, > > If I understand the question properly, isn't condition #3 inclusive of > conditions #1 and #2? Basically, if a PRIMARY_ID value contains only > the values 'A' or 'C' then remove all records for that PRIMARY_ID? > > There is probably a shorter way, but I think this works. > > > proc sort data = test; > by primiary_id; > run; > > * identify primary_id values to remove ; > data removes (keep=primary_id); > set test; > by primary_id; > retain a_flag c_flag oth_flag; > if first.primary_id then do; > a_flag = 0; > c_flag = 0; > oth_flag = 0; > end; > if var = 'A' then a_flag = 1; > else if var = 'C' then c_flag = 1; > else oth_flag = 1; > if last.primary_id then do; > if (a_flag or c_flag) and not oth_flag then output; > end; > run; > > * remove primary_id values ; > proc sql; > create table need as > select * > from test > where primary_id not in (select * > from removes) > ; > quit; > > proc print data = need; > run; > > > > > > Jack Clark > Senior Programmer > phone: 410-455-6256 > fax: 410-455-6850 > jclark@hilltop.umbc.edu > > University of Maryland, Baltimore County > Sondheim Hall, 3rd Floor > 1000 Hilltop Circle > Baltimore, MD 21250 > > Please consider the environment before printing this e-mail and/or any > attachments. > > > Confidentiality Notice: This e-mail may contain information that is > legally privileged and that is intended only for the use of the > addressee(s) named above. If you are not the intended recipient, you are > hereby notified that any disclosure, copying of this e-mail, distribution, > or action taken in reliance on the contents of this e-mail and/or documents > attributed to this e-mail is strictly prohibited. If you have received this > information in error, please notify the sender immediately by phone and > delete this entire e-mail. Thank you.-----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 >


Back to: Top of message | Previous page | Main SAS-L page