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 (November 2010, 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 Nov 2010 13:38:04 -0500
Reply-To:   Nat Wooding <nathani@VERIZON.NET>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Nat Wooding <nathani@VERIZON.NET>
Subject:   Re: Lag Function
In-Reply-To:   <BEE008A6-F8E5-414A-AEF6-17E6E423460E@alumni.stanford.org>
Content-Type:   text/plain; charset="US-ASCII"

Jack

It certainly would make life easier and now that you mention it, it looks like it should work but a trial gives

ERROR: No SET, MERGE, UPDATE, or MODIFY statement is present

So there appears to be a rule concerning such. Maybe they figure that the input records are not likely to be in order so there is no use in trying. It might make a good SASWare Ballot suggestion.

Are there any "Birdies" listening today?

Nat

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Jack F. Hamilton Sent: Friday, November 26, 2010 1:29 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Lag Function

I wish we could use FIRST. and LAST. with variables read with the INPUT statement. Maybe there's a syntactical reason why that wouldn't work, but logically it should be possible (maybe with a different syntax).

On Nov 26, 2010, at 4:53 , Nat Wooding wrote:

> Joe > > As I read your code, you want to reset your counting variable whenever a > pair of successive records are different but to increase it when you have > two or more identical records. This is very easily done using if first. type > logic. In my example below, I used Gerhard's modified input statement and > used a different counting variable name just so it would stand out. > > Nat Wooding > > DATA X; > LENGTH KEY $41.; > INPUT CARRIER $ @4 EMP_GRP_NBR : $6. @11 EMP_DIVISION : $4. @16 > CONTRACT_NBR : $9. > @26 MEMBER_NBR : $2.; > > CARDS; > 01 030730 0001 04114422W 00 > 01 030730 0001 04114422W 00 > 01 030730 0001 04434800W 00 > 01 030730 0001 04511270W 00 > 01 030730 0001 04674974W 00 > 01 030730 0001 05142413W 00 > 01 030730 0001 05142413W 02 > 01 030730 0001 051485322 00 > 01 030730 0001 05433318W 00 > 01 030730 0001 05433318W 01 > 01 030730 0001 05433318W 02 > 01 030730 0001 05455620W 00 > 01 030730 0001 05455620W 01 > 01 030730 0001 05455620W 02 > 01 030730 0001 06003971W 00 > 01 030730 0001 06003971W 01 > 01 030730 0001 06042657W 00 > 01 030730 0001 06042657W 02 > 01 030730 0001 06042657W 03 > 01 030730 0001 06042657W 04 > 01 030730 0001 06042657W 05 > 01 030730 0001 06266051W 00 > 01 030730 0001 06266051W 01 > 01 030730 0001 062705974 00 > 01 030730 0001 062705974 02 > 01 030730 0001 062705974 03 > 01 030730 0001 111502697 00 > 01 030730 0001 111502697 01 > 01 030730 0001 111502697 02 > 01 030730 0001 111502697 03 > 01 030730 0001 111502697 05 > 01 030730 0001 261711943 00 > 01 030730 0001 261711943 02 > 01 030730 0001 261711943 03 > 01 030730 0001 261711943 04 > 01 030730 0001 261740277 00 > 01 030730 0001 262764072 00 > 01 030730 0001 262764072 01 > RUN; > Data Y; > set x; > by CARRIER EMP_GRP_NBR EMP_DIVISION CONTRACT_NBR MEMBER_NBR; > if first.member_nbr then MemberCount = 1;else MemberCount+1; > run; > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > SUBSCRIBE SAS-L Joe H. Smith > Sent: Friday, November 26, 2010 1:55 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Lag Function > > Hi all , > > I am using the below code ,but in my output i am unable to get correct > value for MCNT.For second observation MCNT value should be 2. > > DATA X; > LENGTH KEY $41.; > INPUT CARRIER $ @5 EMP_GRP_NBR $ @13 EMP_DIVISION $ @21 CONTRACT_NBR $9. > @33 MEMBER_NBR $; > retain mcnt 1; > IF CARRIER NE LAG(CARRIER) THEN MCNT= 1; > ELSE IF EMP_GRP_NBR NE LAG(EMP_GRP_NBR) THEN MCNT= 1; > ELSE IF EMP_DIVISION NE LAG(EMP_DIVISION) THEN MCNT= 1; > ELSE IF CONTRACT_NBR NE LAG(CONTRACT_NBR) THEN MCNT=1; > ELSE IF MEMBER_NBR NE LAG(MEMBER_NBR) THEN MCNT=1; > ELSE MCNT=MCNT + 1; > CARDS; > 01 030730 0001 04114422W 00 > 01 030730 0001 04114422W 00 > 01 030730 0001 04434800W 00 > 01 030730 0001 04511270W 00 > 01 030730 0001 04674974W 00 > 01 030730 0001 05142413W 00 > 01 030730 0001 05142413W 02 > 01 030730 0001 051485322 00 > 01 030730 0001 05433318W 00 > 01 030730 0001 05433318W 01 > 01 030730 0001 05433318W 02 > 01 030730 0001 05455620W 00 > 01 030730 0001 05455620W 01 > 01 030730 0001 05455620W 02 > 01 030730 0001 06003971W 00 > 01 030730 0001 06003971W 01 > 01 030730 0001 06042657W 00 > 01 030730 0001 06042657W 02 > 01 030730 0001 06042657W 03 > 01 030730 0001 06042657W 04 > 01 030730 0001 06042657W 05 > 01 030730 0001 06266051W 00 > 01 030730 0001 06266051W 01 > 01 030730 0001 062705974 00 > 01 030730 0001 062705974 02 > 01 030730 0001 062705974 03 > 01 030730 0001 111502697 00 > 01 030730 0001 111502697 01 > 01 030730 0001 111502697 02 > 01 030730 0001 111502697 03 > 01 030730 0001 111502697 05 > 01 030730 0001 261711943 00 > 01 030730 0001 261711943 02 > 01 030730 0001 261711943 03 > 01 030730 0001 261711943 04 > 01 030730 0001 261740277 00 > 01 030730 0001 262764072 00 > 01 030730 0001 262764072 01 > RUN; > > Please help out. > > Thanks & Regards, > MIKE


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