Guys guys
I included a screenshot to help clarify my problem:
http://i40.tinypic.com/mcrnmv.jpg .
I am trying to calculate some moving average and moving standard deviation. The thing is, I want to calculate the coefficient of variation (stdev / avg) for the actual value. This is usually done by calculating stdev and avg over the last 5 years. However, sometimes there are observations in my database for which I have no information over the past 5 years (maybe only 3, 2, etc.). That is why I want a code that will compute avg and stdev, even if there is no information for all 5 years.
In addition, as you see in the observations, sometimes I have information for more than 5 years, when this is the case, I need some kind of moving average that allows me to calculate avg and stdev over the past 5 years. Therefore, if a company has information for 7 years, I need some code that calculates avg and stdev, say, 1997 (1991-1996), 1998 (1992-1997) and 1999 (1993-1998).
Since I am not very familiar with sas commands, it should look (very rude):
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 idea, I'll try to figure it out, but it's worth publishing it if I don't find it myself.
Thank!
source
share