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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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