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 2009, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 29 May 2009 09:25:18 -0400
Reply-To:   Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject:   Re: need a sas function analagous to LAG function

a function is not possible to do that. How should SAS know what comes next? Remembering previous obs is no problem, but looking forward before reading the obs is impossible with one SET. That would need 2 PDVs and a possibility to choose which one to use. Here is another possibility which uses also a second SET and direct access:

data test; set sashelp.class end=fin; n=_n_+1; if not fin then do; set sashelp.class (rename=height=next_height) point=n; end; else next_height=.; two_heights = sum(height, next_height); keep two_heights height next_height; run;

If you don't test for the last obs, the POINT= tries to access a not- existant obs. Gerhard

On Fri, 29 May 2009 09:05:03 -0400, Mike Zdeb <msz03@ALBANY.EDU> wrote:

>hi ... here's one way > >SASHELP.CLASS has 19 observations ... the new data set will have 18 > >data test; >set sashelp.class; >set sashelp.class (firstobs=2 rename=(height=next_height)); >two_heights = sum(height, next_height); >keep two_heights height next_height; >run; > >proc print data=test; >var height next_height two_heights; >run; > >-- >Mike Zdeb >U@Albany School of Public Health >One University Place >Rensselaer, New York 12144-3456 >P/518-402-6479 F/630-604-1475 > >> Hello All, >> >> I am familiar with the LAG function. It allows you to use a value of a >> variable from the previous observation in hte calculation of a value of a >> variable for the current observation. >> >> What I need to to is if there is a function which allows you to take a >> value of a variable in the NEXT observation and use it in operations on the >> current observation. If so, what is it? >> >> For example, I want to take the value of the variable UNIT in from the >> observation that follows my current one and assign it to a new variable in >> the current observation. >> >> something like: >> >> if unit='.' then unit1=next(unit); >> >> I don't think "next" is what i want, but what is? >> >> Thanks, >> >> Randall >>


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