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 (January 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 28 Jan 2011 09:52:20 -0600
Reply-To:   Joe Matise <snoopy369@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Joe Matise <snoopy369@GMAIL.COM>
Subject:   Re: Leading average from lag data
Comments:   To: Navi R <navi.mmxi@gmail.com>
In-Reply-To:   <201101281503.p0SBlP1a006018@waikiki.cc.uga.edu>
Content-Type:   text/plain; charset=ISO-8859-1

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.

-Joe

On Fri, Jan 28, 2011 at 9:03 AM, Navi R <navi.mmxi@gmail.com> wrote:

> data demand; > input year demand; > cards; > 2005 80 > 2006 85 > 2007 78 > 2008 92 > 2009 87 > ; > run; > > 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 > times > 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, > Navi >


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