BookmarkSubscribeRSS Feed
BCNAV
Quartz | Level 8

I have a time series that I have run X11 on and have the resulting seasonal factors. I would like to create an average seaonal factor series for each seassonal factor. This means that each month will be the average of all other seasonal factors for that month.

 

For example, if the seasonal factors for January for a time series variable are:

 

Jan1999 5

Jan2000 10

Jan2001 15

Jan2002 20

 

Then the new average seasonal factor series will be the average of all January seasonal factors (5+10+15+20)/4=12.5. The same would be done for all 12 months. The output for this example would be

 

Jan1999 12.5

Jan2000 12.5

Jan2001 12.5

Jan2002 12.5

 

and so on. February would be the average of all other Februarys.

 

I tried proc means with class as my date, but this did not work.

 

Any ideas?

2 REPLIES 2
KachiM
Rhodochrosite | Level 12

Do you want a data step?

 

Have 2 _temporary_  arrays, one(K) to hold the sum of VALs and another to hold the count of values added to each of 12 cells.

In the first pass of input data set, build the 2 arrays. In the second pass replace the values by the average computed using K[i] / C[i] where i = 1 to 12. If i-th cell is missing do not write out.

 

 

ballardw
Super User

Try your means code with

 

Format <name of the data variable> monname3.;

 

You should get your cross year means and the date will look like Jan, Feb, Mar, ... , Dec.

 

You would have to do something else to merge back onto multiple records but you haven't shown quite enough information abou tyour data, variable names/types and such.

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

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
  • 2 replies
  • 887 views
  • 0 likes
  • 3 in conversation