Calculating moving average/stdev in SAS?

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-03-17T09:17:03Z Indexed on 2010/03/17 9:21 UTC
Read the original article Hit count: 248

Filed under:
|
|
|

Hye guys,

I included a screenshot to help clarify my problem:

http://i40.tinypic.com/mcrnmv.jpg.

I'm trying to calculate some kind of moving average and moving standard deviation. The thing is I want to calculate the coefficients of variation (stdev/avg) for the actual value. Normally this is done by calculating the stdev and avg for the past 5 years. However sometimes there will be observations in my database for which I do not have the information of the past 5 years (maybe only 3, 2 etc). That's why i want a code that will calculate the avg and stdev even if there is no information for the whole 5 years.

Also, as you see in the observations, sometimes I have information over more than 5 years, when this is the case I need some kind of moving average which allows me to calculate the avg and stdev for the past 5 year. So if a company has information for 7 years I need some kind of code that will calculate the avg and stdev for, lets say, 1997 (by 1991-1996), 1998 (by 1992-1997) and 1999 (1993-1998).

As i'm not very familiar with sas commands it should look (very very roughly) like:

set var
if year = i then stdev=stdev(year(i-6) untill year(i-1)) and average = avg(year(i-6) untill year(i-1))

Or something like this, I really have no clue, I'm gonna try and figure it out but it's worth posting it if I won't find it myself.

Thanks!

© Stack Overflow or respective owner

Related posts about sas

Related posts about standard