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. 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 807 views
  • 0 likes
  • 2 in conversation