BookmarkSubscribeRSS Feed
jdub
Calcite | Level 5
I have a monthly time series and want to make quarterly observations. I started by assigning observations to quarters and thought to somehow use proc means to generate the average value of each trio of year-quarter values. How do I use proc means to create mean values where of all like year and quarter values?

data structure:
year month quarter value
1992 1 2 x
1992 2 2 y
1992 3 2 z
1992 4 3 a
1992 5 3 b
1992 6 3 c

Goal: use proc means to calc:
(x + y z) / 3 , (a + b + c) / 3
3 REPLIES 3
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Jdub,

This is a solution:
[pre]
data i;
input year month quarter value;
datalines;
1992 1 2 10
1992 2 2 11
1992 3 2 12
1992 4 3 21
1992 5 3 22
1992 6 3 23
run;
proc means data=i nway noprint;
output out=Mean(drop=_:) Mean=Mean;
var value;
class Year Quarter;
run;
[/pre]
Sincerely,
SPR
jdub
Calcite | Level 5
SPR,

Thank you for the soln. I navigated my way to a less elegant soln. I concatenated year and quarter and used:
proc means data=i;
class=yrqt;
var=value;
output out=Meanvalue Mean=value;
run;

For the sake of learning, why did you specify nway? Can class work on combinations of variables like Year Quarter - don't they need to be concatenated? I am guessing you used nway b.c. you have two classes, yes?
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Jdub,

Look at nway description in SAS help it explains the use of nway in detail.

"I am guessing you used nway b.c. you have two classes, yes?" it does not matter how many classes do you have. For example, in your code you have only one class but Meanvalue contains means for total dataset (not divided in classes for _type_=0 ) and for each value of the class (_type_=1). If you add nway option then only means for different values of class variable are calculated. If you have several classes then with nway option proc means calculates means for all combinations of class values.

Sincerely,
SPR

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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