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 (May 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sun, 2 May 2004 19:15:05 -0400
Reply-To:   Quentin McMullen <quentin_mcmullen@BROWN.EDU>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Quentin McMullen <quentin_mcmullen@BROWN.EDU>
Subject:   Re: Find out all firms with the same id and same icode
Comments:   To: sportsfun77@HOTMAIL.COM

On Sun, 2 May 2004 09:34:16 -0700, sportsfun <sportsfun77@HOTMAIL.COM> wrote:

>Hi, > >My data looks like this: > >ID ICODE NUM; >1000 2000 3 >1000 2000 3 >1000 2000 3 >1001 2020 2 >1001 1010 2 >1002 1010 3 >1002 1010 3 >1002 1020 3 > >ID is the firm id, ICODE is another variable, NUM is the number of >firms that share the same id. I want to find out that for all firms >that share the same id, if they also share the same icode (for example >for id 1000), I will put them in a separate dataset. For all the other >firms (e.g., id 1001 and 1002), not all the firms share the same id >also share the same icode, I will put them in a different dataset. How >can I do this? > >Thanks a lot! > >Fun

I see you've already got an array response. Here are a couple other methods, and there are yet more (as always)...

data a; input id icode num; cards; 1000 2000 3 1000 2000 3 1000 2000 3 1001 2020 2 1001 1010 2 1002 1010 3 1002 1010 3 1002 1020 3 ; run;

*I just read Howard Schreier's NESUG 2003 paper on the self-interleave; *Below is my first attempt, so user beware ;

data sameicode difficode; set a (in=preview) a ; retain dif firstIcode; by id; if preview then do; if then do; dif=0; firstIcode=icode; end; else if icode ne firstIcode then dif=1; end; else do; if dif=1 then output difficode; else output sameicode; end; drop firstIcode dif; run;

*and also a quick-n-dirty SQL solution; *note the max() and min() functions will ignore missings, not an issue; *in the sample data ;

proc sql; create table same as select * from a group by id having max(icode)=min(icode) ; create table diff as select * from a group by id having max(icode) ne min(icode) ; quit;

Kind Regards, --Quentin

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