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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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