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 (May 1998, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 19 May 1998 17:20:54 -0400
Reply-To:     "Zuckier, Gerald" <Zuckier@CHIME.ORG>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         "Zuckier, Gerald" <Zuckier@CHIME.ORG>
Subject:      Re: Lag Function Question
Comments: To: Kathy Chi-Burris <kathy.chi-burris@AGOURON.COM>
Content-Type: text/plain

Sure. This oughta do it (not tested). If you put the lag statement inside the conditional, it only gets triggered whenever that branch of the conditional gets triggered. Not exactly what you might expect.....

> data testall; lagc=lag(c); > set test; > by A B; > if first.A then D = .; > else D=lagC; drop lagc; > run; > > ---------- > From: Kathy Chi-Burris[SMTP:kathy.chi-burris@AGOURON.COM] > Sent: Tuesday, May 19, 1998 4:46 PM > To: SAS-L@UGA.CC.UGA.EDU > Subject: Lag Function Question > > Can anybody tell me that why the following program gives me results in > OUTPUT1 instead of OUTPUT2? > To obtain results in OUTPUT2, I have to get D=lag(C) for all > observations first and then go back to set the first.A to missing. Is > there a better way? > > > data test; > input A B C; > cards; > 1 1 3 > 1 2 6 > 1 3 5 > 1 4 7 > 1 5 8 > 2 1 1 > 2 2 2 > 2 3 6 > ; > run; > > data testall; > set test; > by A B; > if first.A then D = .; > else D=lag(C); > run; > > proc print; > run; > > > > <<< OUTPUT 1 >>> > > OBS A B C D > 1 1 1 3 > 2 1 2 6 > 3 1 3 5 6 > 4 1 4 7 5 > 5 1 5 8 7 > 6 2 1 1 > 7 2 2 2 8 > 8 2 3 6 2 > > <<< OUTPUT 2 >>> > > OBS A B C D > 1 1 1 3 > 2 1 2 6 3 > 3 1 3 5 6 > 4 1 4 7 5 > 5 1 5 8 7 > 6 2 1 1 > 7 2 2 2 1 > 8 2 3 6 2 >


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