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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.