Hey guys,
What is wrong with my macro? Can't seem to run it, only get black text in the editor screen.
I have a dataset with one variable diff, and i wan't to find the constant growth for a subseries of windows of 8 observations.
For each regression i want to save the output residuals.
%macro lol;
%do i=1 %to 36;
proc reg data = data.test (firstobs = &i obs = &i + 7);
model dif = ;
output out = data.lol&i;
r = 1975 + &i
run;
%end;
%mend lol;
Thanks
So RESIDUALS is key word on the OUTPUT statement, not a separate statement.
It tells the proc what variable name to use for to store the residual value. So again you cannot have a variable name that starts with a number or has a plus sign embedded in it.
proc reg data = data.test (firstobs = &i obs = %eval(&i + 7) );
model dif = ;
output out = data.lol&i
r = res_%eval(1975 + &i)
;
run;
Your proc reg isn't valid SAS code.
Get a working version of your proc reg and then embed it in a loop.
Could you elaborate?
the proc reg works without the macro and do loop.
Can you post a log of your reg code working? There is no R statement as far as I'm aware.
You cannot use OBS=1+7 in a dataset option. You could use %EVAL() to have the macro processor convert that to 8 instead.
What is the R= statement in your PROC REG code? Are you trying to calculate a new variable? Even if PROC REG allowed that it would be a constant for each regression and so not add anything to the regression model.
Hey Tom,
You are right, i will try with the %eval.
The R = should give me a new variable for the residuals. It works when performing a single regression.
RESIDUAL | R=names
residuals, calculated as ACTUAL minus PREDICTED
Thanks.
So RESIDUALS is key word on the OUTPUT statement, not a separate statement.
It tells the proc what variable name to use for to store the residual value. So again you cannot have a variable name that starts with a number or has a plus sign embedded in it.
proc reg data = data.test (firstobs = &i obs = %eval(&i + 7) );
model dif = ;
output out = data.lol&i
r = res_%eval(1975 + &i)
;
run;
Thanks a lot Tom.
3 main errors in your code:
1. &i+7 needs the %eval function to resolve
2. Proc Reg has no R= statement
3. Model Dep= results in an intercept only model, I think that would be the difference from the mean of the results. Not sure what the need would be for that, but if its what your looking for I guess that's fine.
Hey Reeza, appreciate the answers.
1) I will try and do that
2) It should give me the residuals -
RESIDUAL | R=names
residuals, calculated as ACTUAL minus PREDICTED
3) Yeah, i know, i actuallly only need the residuals from the regression, for further calculations.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.