| Date: | Tue, 3 Oct 2006 10:04:03 -0400 |
| Reply-To: | "data _null_;" <datanull@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "data _null_;" <datanull@GMAIL.COM> |
| Subject: | Re: By group processing |
|
| In-Reply-To: | <1159883611.513060.154130@b28g2000cwb.googlegroups.com> |
| Content-Type: | text/plain; charset=ISO-8859-1; format=flowed |
I'm no expert but this is more easily done using SQL as follows.
proc sql feedback;
select * from work.test
where id in(select distinct(id) from work.test
where code in('apple','orange','lemon'));
quit;
run;
id code
------------------
1111 apple
1111 orange
1111 lemon
3333 apple
3333 yellow
3333 orange
4444 grey
4444 white
4444 orange
On 10/3/06, 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;
>
|