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:
set sashelp.class end=fin;
if not fin then do;
set sashelp.class (rename=height=next_height) point=n;
two_heights = sum(height, next_height);
keep two_heights height next_height;
If you don't test for the last obs, the POINT= tries to access a not-
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
>set sashelp.class (firstobs=2 rename=(height=next_height));
>two_heights = sum(height, next_height);
>keep two_heights height next_height;
>proc print data=test;
>var height next_height two_heights;
>U@Albany School of Public Health
>One University Place
>Rensselaer, New York 12144-3456
>> 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
>> 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
>> 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
>> the current observation.
>> something like:
>> if unit='.' then unit1=next(unit);
>> I don't think "next" is what i want, but what is?