knowledge-database (beta)

Current group: comp.soft-sys.sas

Re: Q on using lag function in a running total scenario

Re: Q on using lag function in a running total scenario  
Schwarz, Barry A
From:Schwarz, Barry A
Subject:Re: Q on using lag function in a running total scenario
Date:21 Jan 05 21:26:20 GMT
DATA new;
SET old;
IF _N_ = 1 THEN
var3 = var1 + var2;
var3 = var1 + var2 + lag(var3);
RUN;

-----Original Message-----
From: RAHUL CHAHAL [mailto:rahulchahal@YAHOO.COM]
Sent: Friday, January 21, 2005 12:03 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Q on using lag function in a running total scenario


Hi,
Would like the SAS experts to help with a seemingly simple question
which I am trying to solve:

id var1 var2
1 100 5
2 110 3
3 119 10
4 122 7
5 130 5

Would like the solution to look like
id var1 var2 var3
1 100 5 105 <- 100+5
2 102 3 108 <- 105+3
3 105 10 118 <-108+10
4 110 7 125 <-118+7
5 114 5 130 <- 125+5

Var3 is the sum of var2 and lag of var3.
Would appreciate help with some pointers. I am using first.id to solve
it with lag function but am probably missing a step since the increment
I am looking for with each step is not happening.

Rahul




---------------------------------
Do you Yahoo!?
Yahoo! Search presents - Jib Jab's 'Second Term'
   

Copyright © 2006 knowledge-database   -   All rights reserved