Date: Thu, 18 Nov 2004 04:13:10 -0800
Reply-To: Dennis Diskin <diskin@SNET.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dennis Diskin <diskin@SNET.NET>
Subject: Re: lag1() question
In-Reply-To: <20041118044125.79499.qmail@web60602.mail.yahoo.com>
Content-Type: text/plain; charset=us-ascii
Jason,
As John Kirpatrick pointed out, LAG(t) returns the value of T at the last call to the lag function. In your example, the first time LAG is called is on the second pass thru the datastep. LAG(T) at that point is missing.
I generally try to avoid LAG entirely unless it is a very simple case.
You could easilly do:
t = .8 ** (_n_ - 1);
HTH,
Dennis Diskin
Jason Zhang <qiyuzhang2@YAHOO.COM> wrote:
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 all-new My Yahoo! - Get yours free!
http://my.yahoo.com