Date: Fri, 29 May 2009 09:36:12 -0400
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: need a sas function analagous to LAG function
On Fri, 29 May 2009 08:49:35 -0400, Randall Powers <powers_r@BLS.GOV>
wrote:
...
>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?
...
>if unit='.' then unit1=next(unit);
>I don't think "next" is what i want, but what is?
...
Hi,
It is quite a common misconception. The short answer is that there is no
next() nor lead() function. And I am afraid that your usage of the lag()
function seems incorrect. For example, if you do, as you suggest:
if missing(unit) then unit1 = lag(unit);
then you will be disappointed and puzzled by the results. The lag()
function cannot retrieve the previous observation value unless the value is
stored there in the first place, because it is a simple queue.
There are many papers written on this subject. For a recent one, see this
nice one by Ian at http://tinyurl.com/kmc76h or
http://www.sesug.org/SESUGOrganization/newsletters/fall2008/Ian_Whitlock_20
0809.pdf. I am naturally partial to Toby and Chang's "award winning" :-)
PharmaSUG2005 paper available at Lex's site http://tinyurl.com/mwqrw9 or
http://www.lexjansen.com/pharmasug/2005/tutorials/tu09.pdf .
For more advanced use of lag() function, a must read is Howard's the
conditional lags (http://www.howles.com/saspapers/CC33.pdf). HTH.
Cheers,
Chang
|