BookmarkSubscribeRSS Feed
6071
Fluorite | Level 6

Hello,

I have 90 lines of data.  I want to calculate the mean and some other metrics for the first 35 years of data, then for years 2-36, then 3-37, etc and then view all of these mean series.  How do I do this?  Thanks very much for your help.

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Can you show us your data?

PaigeMiller
Diamond | Level 26

One method is using a multilabel format

 

Example:

 

proc format;
    value yearf (multilabel) 
        1-35='1-35'
        2-36='2-36'
        3-37='3-37'
        /* I'm lazy, you type the rest */
;
run;

proc summary data=have nway;
    class year_since_start/mlf format=yearf.;
    var some_other_variables;
    output out=_stats_ mean= std= min= max=/autoname;
run;

Another method, if you have SAS/ETS and PROC EXPAND, is to calculate moving averages of length 35 based upon your year variable. Probably less typing.

--
Paige Miller
Reeza
Super User
Moving average or rolling average is the term to use in Google for this, but it depends on how your data is structured.
If you have SAS/ETS this is quite easy, but also very doable within a data step as well.

SAS/ETS example of 12 month moving average
https://gist.github.com/statgeek/07a3708dee1225ceb9d4aa75daab2c52

Data step, array approach
https://gist.github.com/statgeek/27e23c015eae7953eff2

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1137 views
  • 0 likes
  • 4 in conversation