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 (February 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 6 Feb 2007 07:54:45 -0500
Reply-To:     Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Subject:      Re: counter variable
Comments: To: Simon Chang <syner@PCHOME.COM.TW>

Simon

with one obvious typing error (marked) in the message, are there more that I have not seen?

If count is not correct, check that you don't have a variable named count, in the dataset you are reading

Why not simplify this to something like

data count; set a( drop=count); by id; if first.id then count= 0 ; count+1; last_id= last.id ; run;

Peter Crawford

On Tue, 6 Feb 2007 03:59:46 -0500, Simon Chang <syner@PCHOME.COM.TW> wrote:

>Hellow: > >I got a problem in counting as well. >I had no idea about why this would happen! >Could any body help me!! > >Thanks in advance! > >Simon > >Here is my SAS code below. > >(A) >proc sort data=a; by id; >Data count; > set a; > by id; > retain count 0; > if first.id then count=0; > count=count+1; > if last.count then last_id=1; else last_id=0; ........^^^^^^^^^ ........

count is not a by variable, so last.count is a syntax error >run; > >OR: >(B) >data count; > set a; > count+1; > by id; > if first.id then count=1; > if last.id then last_id=1; else last_id=0; >run; > > >(C)Result: >(the numbers with * are completly wrong!!!) >ID count last_id >A 1 0 >A 2 0 >A 2* 1 >B 1 0 >B 2 1 >C 1 0 >C 3* 1


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