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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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