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 (October 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 26 Oct 2007 06:05:16 -0700
Reply-To:     Peter <crawfordsoftware@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter <crawfordsoftware@GMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: assign the same ids for the same by variables
Comments: To: sas-l@uga.edu
In-Reply-To:  <6.2.3.4.2.20071025124452.056a08e0@postoffice7.mail.cornell.edu>
Content-Type: text/plain; charset="us-ascii"

On 25 Oct, 17:45, f...@CORNELL.EDU (Florio Arguillas) wrote: > Hi Wang, > > Try this one. > > Best regards, > > Florio > > data have; > infile cards; > input identity_num $; > cards; > A > A > A > B > B > C > C > C > C > D > D > ; > > data need; > set have; > by identity_num; > if first.identity_num then study_id+1; > run; > > At 11:56 AM 10/25/2007, Ai Hua Wang wrote: > > > > >Hi List: > > >I have searched the listserve archive. But for some reason I could > >not find anything. This is probably because my key words are not > >appropriate. Could anybody in the list help me on the following > >task? I need to assign the same ids for the the same by variables. I > >list the sample data in the following: > > >identity_num > >A > >A > >A > >B > >B > >C > >C > >C > >C > >D > >D > > >I want the output looks like the following: > > >identity_num study_id > >A 1 > >A 1 > >A 1 > >B 2 > >B 2 > >C 3 > >C 3 > >C 3 > >C 3 > >D 4 > >D 4 > > >I write the following SAS codes to accomplish the task. But I got > >errors. I guess the errors are caused by the do loop. I need your > >help on fixing the do loop. I am sorry this is probably a very simple question. > > >Thanks, > >Wang > > >data out1; > >by identity_num; > >set have; > >n=1; > >length study_id 3; > >do j=first.identity_num to last.identity_num; > >study_id = n; > >n+1; > >end; > >run; > > >__________________________________________________ > >Do You Yahoo!? > >Tired of spam? Yahoo! Mail has the best spam protection around > >http://mail.yahoo.com- Hide quoted text - > > - Show quoted text -

lets get brief. use the special features provided with by-group processing in a data step - - first.{by-variable} That will be true(=1) when the obs read is first for the study group, otherwise false(=0).

data wanted; set have; by identity_num ; study_id + first.identity_num ; run;

Reduced to the size of the problem, by Peter.C


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