BookmarkSubscribeRSS Feed
srikanthyadav44
Quartz | Level 8

dear all 

i have to compute average of a variable in panel data set on rolling basis.

Earlier, i used the following commond to compute rolling standard deviation as suggested by the members in this community and it worked well. 

roc sql;
   create table want as
   select *, 
          (select std(sales) from have 
             where Company_Name=a.Company_Name
               and a.year-5 le year le a.year)
                 as stddev format=8.2
   from have as a;
quit;

please let me know, what changes i have to do to compute rolling average for the same dataset. 

 

thanks in advance 

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

Simply change the function std to mean like this

 

proc sql;
   create table want as
   select *, 
          (select mean(sales) from have 
             where Company_Name=a.Company_Name
               and a.year-5 le year le a.year)
                 as MovAv format=8.2
   from have as a;
quit;

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
  • 1 reply
  • 579 views
  • 0 likes
  • 2 in conversation