Date: Fri, 4 Nov 2005 09:50:08 -0800
Reply-To: Friar Broccoli <EliasRK@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Friar Broccoli <EliasRK@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Create a Roll Over Sum
In-Reply-To: <1131122041.736046.246750@z14g2000cwz.googlegroups.com>
Content-Type: text/plain; charset="iso-8859-1"
YI wrote:
> Can anyone guide me how to figure out the following problem? Having a
> certain variable of data, I want to create another variable that sums
> up previous certain number of rows (including the current row) at each
> line.
> For example:
> With data Var1, and starting at row Three (say everything 3 steps), I
> want to create a variable Var2 that sums up previous 2 consecutive rows
> and the current row of Var1.
> Like the following:
> Var1 Var2
> 1
> 2
> 3 6 <-- sum(1+2+3)
> 4 9 <-- sum(2+3+4)
> 5 12 ... ...
> 6 15
> 7 18
> 8 21
> 9 24 <--sum(7+8+9)
>
> Thanks!
How about creating an array of 3 and just moving the contents.
Something LIKE:
array MySum(3);
Var2 = MySum(1) + MySum(2) + MySum(3);
MySum(3) = MySum(2);
MySum(2) = MySum(1);
MySum(1) = Var1;
Not very elegant, but personally I prefer being clear.
Cordially;
Keith Elias
|