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 (October 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 3 Oct 2006 10:12:17 -0400
Reply-To:   Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Subject:   Re: By group processing

On Tue, 3 Oct 2006 10:01:08 -0400, Peter Crawford <peter.crawford@BLUEYONDER.CO.UK> wrote:

>On Tue, 3 Oct 2006 06:53:31 -0700, Newbie <oldscot82@YAHOO.COM> wrote: > >>data test; >>input id$ code$; >>datalines; >>1111 apple >>1111 orange >>1111 lemon >>2222 green >>2222 yellow >>2222 banana >>2222 pink >>3333 apple >>3333 yellow >>3333 orange >>4444 grey >>4444 white >>4444 orange >>5555 red >>5555 blue >>5555 green >>; >>run; >>/* >>Hi, >>In the above dataset, I am trying to extract all ID's that >>have any of these codes(apple,orange,lemon). >>If the ID has any of those codes, I would like to extract all records >>for that ID; >>Thanks for your help. >> >>My final dataset would look like this. >>1111 apple >>1111 orange >>1111 lemon >>3333 apple >>3333 yellow >>3333 orange >>4444 grey >>4444 white >>4444 orange >> >>Here is what I have got so far >> >>proc sort data=test; >>by id; >>run; >> >>data test2 ; >>set test; >>by id; >>retain count; >>if first.id then do; >>count=0; >>end; >>if code in ('apple','orange','lemon') then do ; >>count+ 1; >>end; >> >>run; > >time to learn about > where > >data wanted ; > set test ; > where code in ('apple','orange','lemon') ; >run; > >Of course, if instead of the original data, you want counts, >put that "where statement" into proc freq > >Good Luck > >Peter Crawford

sorry... mea culpa

this old scot still needs to learn to read before responding !

Not just individuals where found, but the whole ID-group when any in the group are found .

Multi-pass is perhaps neccessary, but since the data is in ID-order this extract can merge fruit wanted, with all the details, by ID data test2 ; merge test( in= wanted where= ( code in ('apple','orange','lemon') ) ) test ; by ID ; if wanted ; run;

Peter


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