Date: Tue, 2 Sep 2008 00:53:50 -0700
Reply-To: Daniel Nordlund <djnordlund@VERIZON.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Daniel Nordlund <djnordlund@VERIZON.NET>
Subject: Re: generating consecutive integers for each group using SAS
In-Reply-To: <cf3ed426-57f1-4f14-8578-ae991d756b79@m73g2000hsh.googlegroups.com>
Content-type: text/plain; charset=utf-8
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of oercim
> Sent: Tuesday, September 02, 2008 12:33 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: generating consecutive integers for each group using SAS
>
> hello. I have a problem. Using SAS programming I want to do that: I
> have such a data column(let labeled 'A'):
> A
> ---
> a
> a
> a
> b
> b
> b
> b
> c
> d
> d
> Now, I want to generate consecutive integers for each group such
> that
> A B
> --- ----------
> a 1
> a 2
> a 3
> b 1
> b 2
> b 3
> b 4
> c 1
> d 1
> d 2
> how can i generate this integers using SAS programming? thanks a lot
*create sample data;
data have;
input A $;
cards;
a
a
a
b
b
b
b
c
d
d
;
run;
*create new variable and dataset;
data want;
set have;
by A;
if first.A
then B=1;
else B+1;
run;
proc print;
run;
Hope this is helpful,
Dan
Daniel Nordlund
Bothell, WA USA
|