DATA Step, Macro, Functions and more

creating quarterly obs for a monthly time series

Reply
Contributor
Posts: 33

creating quarterly obs for a monthly time series

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
Super Contributor
Super Contributor
Posts: 365

Re: creating quarterly obs for a monthly time series

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=_Smiley Happy Mean=Mean;
var value;
class Year Quarter;
run;
[/pre]
Sincerely,
SPR
Contributor
Posts: 33

Re: creating quarterly obs for a monthly time series

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?
Super Contributor
Super Contributor
Posts: 365

Re: creating quarterly obs for a monthly time series

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
Ask a Question
Discussion stats
  • 3 replies
  • 165 views
  • 0 likes
  • 2 in conversation