BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hamudi
Calcite | Level 5

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 Smiley Happy

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

9 REPLIES 9
Reeza
Super User

Your proc reg isn't valid SAS code.

Get a working version of your proc reg and then embed it in a loop.

hamudi
Calcite | Level 5

Could you elaborate?

the proc reg works without the macro and do loop.

Reeza
Super User

Can you post a log of your reg code working? There is no R statement as far as I'm aware.

Tom
Super User Tom
Super User

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.

hamudi
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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;

hamudi
Calcite | Level 5

Thanks a lot Tom.

Reeza
Super User

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.

hamudi
Calcite | Level 5

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2262 views
  • 1 like
  • 3 in conversation