Programming the statistical procedures from SAS

Rewrite Macro rolling regression for output

Reply
Occasional Contributor
Posts: 6

Rewrite Macro rolling regression for output

[ Edited ]

Hello all,

 

I am a new user of Sas but I have to try macro for rolling regression 12 months, shift one month forward. I did this one and it can run well for PROC REG with OUTEST. So I want to rewrite it for getting residual variable from OUTPUT, I tried many times and it is not working in every loop order. I did change one part like this: 

 

proc reg data=&data;
where &date between &idate1 and &idate2;
model &model_equation;
&by_id;
output out=_outest_ds r=resid
run;

%* Add loop date range variables to output set;
data _outest_ds;
set _outest_ds;
regobs= _p_ + _edf_; %* number of observations in regression; I delete this line because edf is from outest, but I changed it into OUTPUT  and do not know how to count regressors. 
date1= &idate1;
date2= &idate2;
%if &year_date=0 %then format date1 date2 date9.;
run;

 

THE CODE THAT I RUN FROM THE LINK BELOW and I can get the results of R-square correctly with rolling window 12 months. 

http://www.lexjansen.com/nesug/nesug07/sa/sa04.pdf

 

I REALLY APPRECIATE YOUR HELP. I AM UNDER STRESSED NOW. 

Nguyen

 

Respected Advisor
Posts: 4,606

Re: Rewrite Macro rolling regression for output

you are missing a semicolon after r=resid 

PG
Occasional Contributor
Posts: 6

Re: Rewrite Macro rolling regression for output

Thank you, I fixed it and there is no result, 0 observations and date 1,
date 2.

The old one, I got the results not in order of loop, they are mess up, I
dont know how to fix it.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Respected Advisor
Posts: 4,606

Re: Rewrite Macro rolling regression for output

Get the code working without any macros first. That will be a lot easier. Then transform back into macro coding.

PG
Occasional Contributor
Posts: 6

Re: Rewrite Macro rolling regression for output

Thank you, I did try it in simple form but the problem is rolling window for proc reg, I cannot create rolling loops because huge data. So I found this one and it works. 

 

Occasional Contributor
Posts: 17

Re: Rewrite Macro rolling regression for output

Hi,

 

What is the code that you used for PROC REG with OUTEST. I am struggling to run a rolling regression for my data as well. I referred to the same article that you did but I dint come up with the right code yet.

Occasional Contributor
Posts: 6

Re: Rewrite Macro rolling regression for output

Hi, you can use the link that I attached below. it can works well.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Ask a Question
Discussion stats
  • 6 replies
  • 187 views
  • 0 likes
  • 3 in conversation