BookmarkSubscribeRSS Feed
gibsonrobb
Calcite | Level 5

I have a data set. I am trying to get the standard deviation for the last ten years for each of my observations. For example, I have data from 1992-2009. So I gathered data from 10 years prior to 1992 to have sufficient data. How do I calculate the STD for each year starting with 1992-2009, by taking the 10 years prior of data? For example, for 1992, I need to see the data from 1983-1992, including data from 1983 and 1992. For 1993, I use data from 1984-1993, and so on. I am trying to do this for each firm, or GVKEY from Compustat. All help appreciated. 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

This is called a "moving standard deviaton". PROC EXPAND will calculate it for you. See this example (where you need to use MOVSTD in place of MOVAVE) https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=etsug&docsetTarget=etsug_...

--
Paige Miller
gibsonrobb
Calcite | Level 5

Thank you, I will take a look and let you know how it goes. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 712 views
  • 0 likes
  • 2 in conversation