Date: Sat, 20 Aug 2011 10:06:03 -0400
Reply-To: Arthur Tabachneck <art297@ROGERS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@ROGERS.COM>
Subject: Re: Groupings --- Is this correct?
If your data are already in ID order why don't you just make both
assignments in one pass. Couldn't you just use something like:
data need ;
set have ;
by ID;
if first.ID then do;
Num_Group = 0 ;
ID_Group+1;
end;
Num_Group+1;
run;
Art
------
On Fri, 19 Aug 2011 23:52:11 -0400, Randy <randistan69@HOTMAIL.COM> wrote:
>Just a variation and this is also what I need. Mind you I have a very big
>data set and I want to keep sorts to a minimum
>
>ID ID_Group
>A 1
>A 1
>A 1
>B 2
>B 2
>B 2
>B 2
>B 2
>C 3
>C 3
>
>
>ID ID_Group Num_Group
>A 1 1
>A 1 2
>A 1 3
>B 2 1
>B 2 2
>B 2 3
>B 2 4
>B 2 5
>C 3 1
>C 3 2
>
>data need ; set have ;
>by ID ID_Group ;
>if first.ID_group then Num_Group = 0 ;
>Num_group + 1 ;
>Run;
>
>Is this correct?
>
>
>
>
>
>
>
>
>
>
>
>
>On Fri, 19 Aug 2011 22:09:46 -0400, Randy <randistan69@HOTMAIL.COM> wrote:
>
>>my data set is as follows:
>>
>>ID
>>A
>>A
>>A
>>B
>>B
>>B
>>B
>>B
>>C
>>C
>>
>>What I need is
>>
>>ID ID_Group
>>A 1
>>A 1
>>A 1
>>B 2
>>B 2
>>B 2
>>B 2
>>B 2
>>C 3
>>C 3
>>
>>The code I wrote is as follows:
>>
>>Data Need ; set Have;
>>by ID;
>>If _N_ = 1 then ID_Group = 0 ;
>>If first.ID then ID_Group +1 ;
>>run;
|