In SAS data step language, LAG5 is the easiest way to do this, along with a
RETAINed sum variable. LAG doesn't actually look back some rows, but builds
a queue, so you can use it going-forward (in a DO loop) just as easily as
you can use it actually looking backwards.
What I'd love to see is how to do this in PROC SQL. Intuitively it should
be easy, but I don't know if there's an easy way to get SQL to spit out a
bunch of new rows without macro looping or some other artificial construct.
On Fri, Jan 28, 2011 at 9:03 AM, Navi R <email@example.com> wrote:
> data demand;
> input year demand;
> 2005 80
> 2006 85
> 2007 78
> 2008 92
> 2009 87
> From the data set above, I would like to calculate the future demand from
> 2010 through 2050 using the moving average of the last 5 years' demand
> an assumed annual growth rate of 5%.
> So, for the year 2010, demand would be ((80 + 85 + 78 + 92 + 87)/5) * 1.05.
> The calculated demand for 2010 will then be used for subsequent year
> calculations and so on.
> Can someone please help me code this in SAS? I am relatively new to SAS.
> Thank you,