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 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 23 May 2008 19:09:52 -0400
Reply-To:   "Howard Schreier <hs AT dc-sug DOT org>" <schreier.junk.mail@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Howard Schreier <hs AT dc-sug DOT org>" <schreier.junk.mail@GMAIL.COM>
Subject:   Re: Sequentially numbering items within the same group

On Fri, 23 May 2008 10:11:43 -0700, Steve Denham <stevedrd@YAHOO.COM> wrote:

>Welcome to the RETAIN statement in the datastep... >The following code actually produced what you want: >data fruit; >input kind $; >cards; >Apple >Apple >Orange >Orange >Orange >Orange >Pear >Pear >Pear >; >proc sort data=fruit; > by kind; >run; >data fruit2;set fruit; > by kind; > if first.kind then fru_count=0; > retain fru_count; > fru_count+1; >run; > >I'll bet you get ten better answers, most involving proc sql,

I doubt it. SQL is not at all well suited for this problem.

>but this one worked for me.Steve Denham >Associate Director, Biostatistics >MPI Research, Inc. >Remove spamblock from header, and replace with stevedrd to reply to me. > > >----- Original Message ---- >From: "" <StephenTGallagher@GMAIL.COM> >To: SAS-L@LISTSERV.UGA.EDU >Sent: Friday, May 23, 2008 12:39:21 PM >Subject: Sequentially numbering items within the same group > >Hello All-- > >I was hoping someone could point me in the right direction regarding >numbering items sequentially that belong to the same group. >Assuming I have a dataset that looks like: > >FRUIT >Apple >Apple >Orange >Orange >Orange >Orange >Pear >Pear >Pear > >I would like to have a dataset which looks like: > >FRUIT FRU_COUNT >Apple 1 >Apple 2 >Orange 1 >Orange 2 >Orange 3 >Orange 4 >Pear 1 >Pear 2 >Pear 3 > >Where each member of the same group has a new variable 'count' that is >incremented for the number of times it is seen. > >I was thinking along the lines of using a sql 'group by' but I wasn't >sure how to iterate through and set the 'FRU_COUNT' variable? > >Any thoughts? > >Thanks-- >sg

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