Help using Base SAS procedures

Monthly rolling average

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Monthly rolling average

Hi Guys,

I am trying to compute monthly rolling averages and my dates are in the format YYYYMM.

Hope someone will be familiar with codes like this.

Thanks!


Accepted Solutions
Solution
‎02-04-2013 01:01 PM
Respected Advisor
Posts: 3,156

Re: Monthly rolling average

Without seeing some sample data, suggestions can't be specific:

1. If you have SAS/ETS, then Proc Expand is your best bet. Rolling Average is just one of its build-in functions.

2. If you choose to use Proc SQL like being suggested, 'group by' needs to be applied on an unique id of every row from t1.

3. Data step, by using temporary array, mod() and/or  'by' processing. Please search 'rolling' or 'moving' in the forum, you will see many posts with similar questions and answers.

Good luck,

Haikuo.

View solution in original post


All Replies
Super Contributor
Posts: 578

Re: Monthly rolling average

its useful to have sample data...but...3 month rolling average

proc sql;

create table want as

select

     t1.dt

     ,avg(t2.....???) as monthly_rolling_avg

from

     want t1

     inner join want t2

           t2.date between intnx('month',t1.date,-3) and t1.date

group by t1.dt;

quit;

Solution
‎02-04-2013 01:01 PM
Respected Advisor
Posts: 3,156

Re: Monthly rolling average

Without seeing some sample data, suggestions can't be specific:

1. If you have SAS/ETS, then Proc Expand is your best bet. Rolling Average is just one of its build-in functions.

2. If you choose to use Proc SQL like being suggested, 'group by' needs to be applied on an unique id of every row from t1.

3. Data step, by using temporary array, mod() and/or  'by' processing. Please search 'rolling' or 'moving' in the forum, you will see many posts with similar questions and answers.

Good luck,

Haikuo.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 204 views
  • 3 likes
  • 3 in conversation