Date: Thu, 18 Nov 2004 08:36:48 0000
ReplyTo: John Kirkpatrick <news@NOSPAM.ISCLTD.CO.UK>
Sender: "SAS(r) Discussion" <SASL@LISTSERV.UGA.EDU>
From: John Kirkpatrick <news@NOSPAM.ISCLTD.CO.UK>
Subject: Re: lag1() question
Jason,
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:
data one;
input x;
cards;
1
2
3
4
5
6
;
run;
data two;
retain t;
set one;
if _n_ eq 1 then t=1;
else t=t*0.8;
run;
proc print data=two;
run;
HTH,
John
"Jason Zhang" <qiyuzhang2@YAHOO.COM> wrote in message
news:20041118044125.79499.qmail@web60602.mail.yahoo.com...
> Hi,
>
> 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:
> T=lag1(t)*0.8;
>
> It doesnĄ¯t work. The following is an example of what
> I want to do:
> data one;
> input x;
> cards;
> 1
> 2
> 3
> 4
> 5
> 6
> ;
> run;
>
> data two;
> set one;
> if _n_=1 then t=1; else
> t=lag1(t)*0.8;
> run;
>
> what I expected for tĄ¯s values are:
> 1
> 0.8
> 0.64
> Ą
>
> Can anyone help me with this? Thanks a lot!!!
> Jason
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> The allnew My Yahoo!  Get yours free!
> http://my.yahoo.com
