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 08:59:04 -0500
Reply-To:     Don Henderson <donaldjhenderson@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
Comments:     RFC822 error: <W> MESSAGE-ID field duplicated. Last occurrence
              was retained.
From:         Don Henderson <donaldjhenderson@HOTMAIL.COM>
Subject:      Re: counter variable
Comments: To: Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
In-Reply-To:  <200702061254.l16BkjvU016919@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"

As usual, Peter's suggestions are spot on.

However, I have another suggestion - use the data step debugger to step thru the logic so you can see where the problem is. Just add /debug to the end of your data statement, e.g.,

data count/debug; /* rest of your step 8/ run;

In case you are not familiar with the debugger, check out:

http://www2.sas.com/proceedings/sugi25/25/btu/25p052.pdf

Found this paper using a quick search at support.sas.com. Other SAS-L folks might have other suggestions for doc on the data step debugger.

HTH, -don h

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Peter Crawford Sent: Tuesday, February 06, 2007 7:55 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: counter variable

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