BookmarkSubscribeRSS Feed
NguyenHa
Calcite | Level 5

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

 

6 REPLIES 6
PGStats
Opal | Level 21

you are missing a semicolon after r=resid 

PG
NguyenHa
Calcite | Level 5
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. -##
PGStats
Opal | Level 21

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

PG
NguyenHa
Calcite | Level 5

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. 

 

Amalik
Calcite | Level 5

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.

NguyenHa
Calcite | Level 5
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. -##

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1954 views
  • 0 likes
  • 3 in conversation