turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- creating quarterly obs for a monthly time series

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-04-2011 04:30 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-04-2011 05:09 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-04-2011 05:30 PM

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?

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-05-2011 09:44 AM

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

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