LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: Jason Zhang <qiyuzhang2@YAHOO.COM>
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 Ą&shy;

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


Back to: Top of message | Previous page | Main SAS-L page