Date: Thu, 18 Nov 2004 08:36:48 -0000
Reply-To: John Kirkpatrick <news@NOSPAM.ISC-LTD.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John Kirkpatrick <news@NOSPAM.ISC-LTD.CO.UK>
Subject: Re: lag1() question
Personally, I always find the lag functions slightly confusing. The
important thing to remember is that lag<n>(x) doesn't return the value of x
n observations ago, but the value of x when lag<n> was called n times ago.
Therefore, conditionally executing lag<n> functions almost always returns
results that you don't expect (in my experience at least!). You ca easily
achieve what you want using thr retain statement:
if _n_ eq 1 then t=1;
proc print data=two;
"Jason Zhang" <qiyuzhang2@YAHOO.COM> wrote in message
> I want to generate a value for a variable, say t. But
> tĄ¯s value depends on previous observationĄ¯s t value.
> I used the code:
> It doesnĄ¯t work. The following is an example of what
> I want to do:
> data one;
> input x;
> data two;
> set one;
> if _n_=1 then t=1; else
> what I expected for tĄ¯s values are:
> Can anyone help me with this? Thanks a lot!!!
> Do you Yahoo!?
> The all-new My Yahoo! - Get yours free!