LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (November 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 3 Nov 2006 02:02:19 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: counter variable
Comments: To: bandaruvijay@GMAIL.COM
In-Reply-To:  <1162513534.777728.7910@f16g2000cwb.googlegroups.com>
Content-Type: text/plain; format=flowed

You dont need the Retain statement as Count + 1 statement has an implied retain statement.

Toby Dunn

You never know what is enough, until you know what is more than enough. ~William Blake, Proverbs of Hell

When the student is ready, the master appears. ~Buddhist Proverb

Only that in you which is me can hear what I'm saying. ~Baba Ram Dass

From: vijay <bandaruvijay@GMAIL.COM> Reply-To: vijay <bandaruvijay@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: counter variable Date: Thu, 2 Nov 2006 16:25:34 -0800

Set the data set by the key variable (patient) and retain the counter variable across all the observations. Increment the counter variable for every observation.Reset the counter to zero for each by group. Code should look something like this.

data dd1; set dd; retain count ; by key; if first.key then count=0; count+1; run;

Thanks Vijay

"Schwarz, Barry A" wrote: > Show your code so we can see what is wrong. > > -----Original Message----- > From: phillyj [mailto:jessica.donato@GMAIL.COM] > Sent: Thursday, November 02, 2006 3:44 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: counter variable > > Hello all! I would be very grateful if someone can help me with this > program: > > I want to create a counter variable that counts 1, 2, 3, etc. for each > observation of each patient. When a new patient arrives I want it to > start back at 1. The below program was created but it is outputting all > the same number for each patient as opposed to a count per patient. > make sense? > > data newOutcomes ; > set Outcomes ; > by patient; > If patient Then record+1 ; > run; > > For instance, this program is outputing > > patient record I would like...... > patient record > 1047 1 > 1047 1 > 1047 1 > 1047 2 > 1047 1 > 1047 3 > 1048 2 > 1048 1 > 1048 2 > 1048 2 > 1048 2 , etc > 1048 3, etc. > > I added a first.patient do loop but it is extracting only the first > patient then... thanks for your help with this.....

_________________________________________________________________ Find a local pizza place, music store, museum and more…then map the best route! http://local.live.com?FORM=MGA001


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