turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- macro do problem

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-11-2015 01:54 PM

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

Accepted Solutions

Solution

01-13-2015
07:02 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hamudi

01-13-2015 07:02 AM

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;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hamudi

01-11-2015 01:57 PM

Your proc reg isn't valid SAS code.

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

01-11-2015 02:07 PM

Could you elaborate?

the proc reg works without the macro and do loop.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hamudi

01-11-2015 02:20 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hamudi

01-11-2015 02:48 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2015 05:48 AM

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.

Solution

01-13-2015
07:02 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hamudi

01-13-2015 07:02 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

01-13-2015 07:07 AM

Thanks a lot Tom.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to hamudi

01-11-2015 03:38 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

01-13-2015 05:46 AM

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.