BookmarkSubscribeRSS Feed
MarkGIP
Calcite | Level 5

Hi everyone!

First of all I want to make clear that I'm fairly new to SAS and the concept of MACROS. So please be patient with me;)

While searching the web I came accross a really helpful MACRO set: DO_OVER annd ARRAY. I adjusted my code and implemented the MACROS at different spots of my code. At first everything worked like a charm until I added a MACRO loop.

Here's a simple example:

%MEND;

/*1. Set Array*/

%ARRAY(REGRESSORS,VALUES=A B);

%MACRO SIMULATION;

%DO MACRO = 1 %TO 2;

/*2. Regression*/

proc reg data=panel;

model y = %DO_OVER(REGRESSORS);

run;

%end;

%MEND SIMULATION;

%SIMULATION;

run;

Since then I always get the following error message for the MACRO inside the loop:

NOTE: Line generated by the macro function "TP".

1 %&MACRO(&&REGRESSORS&I)

-

76


ERROR 22-322: Syntax error, expecting one of the following: a name, ;, /, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_, {.

ERROR 76-322: Syntax error, statement will be ignored.

Hopefully you could help me with this dilemma..... THANK YOU!!!

11 REPLIES 11
Tom
Super User Tom
Super User

Did you try exiting from SAS and starting over with a clean slate?  It is possible you had code before with unbalanced quotes or () and SAS is just confused.

If you are already writing a macro named then there is not much value to using the DO_OVER and ARRAY macros as you can just write normal SAS macro logic code to loop for you.

But in the little bit of code you posted that does not even seem needed.

%MACRO SIMULATION(dataset,REGRESSORS);


proc reg data=&dataset;

model y = &regressors ;

run;

%MEND SIMULATION;


%SIMULATION(panel,A B);

MarkGIP
Calcite | Level 5

Hi Tom,

Thanks for your quick reply. I know that the DO_OVER macro is not needed in the sample code I posted. I just wanted to reproduce the error with a simple example...

I've already restarted SAS a couple of times and rerun the code. The error pops up every time I try:(

Any ideas?

Peter_C
Rhodochrosite | Level 12

Mark

the problem does not occur with my 2006 version of these Ted Clay macros.

I think you will need to check that your version is correct.

MarkGIP
Calcite | Level 5

Hi Peter!

I've downloaded the macros from: http://www.sascommunity.org/wiki/File:Clay-TightLooping-macros.zip. Maybe I'm doing something completely wrong but I have no clue whatsoever...

To give you a better idea, I've extended the original example....

/*1. Create Data*/

Data panel;

do i=1 to 10;

a=i*2;

b=log(i);

c=i;

output;

end;

run;

/*2. Set Array*/

%ARRAY(REGRESSORS,VALUES=a b);

/*3. Regression*/

%MACRO SIMULATION;

%DO MACRO = 1 %TO 2;

proc reg data=panel;

model c = %DO_OVER(REGRESSORS);

run;

%end;

%MEND SIMULATION;

%SIMULATION;

run;

Everytime I run the code I get error message mentioned above...

Peter_C
Rhodochrosite | Level 12

even with the 2007 version of Ted's macros I don't get your error. Perhaps that is because I submit Ted's macros before running your code.

How do you invoke these macros (autocall or submit)?

In what release of SAS are you running the code?

Peter

data_null__
Jade | Level 19

MarkGIP wrote:

Hi everyone!

First of all I want to make clear that I'm fairly new to SAS and the concept of MACROS. So please be patient with me;)

While searching the web I came accross a really helpful MACRO set: DO_OVER annd ARRAY. I adjusted my code and implemented the MACROS at different spots of my code. At first everything worked like a charm until I added a MACRO loop.

Here's a simple example:

%MEND;

/*1. Set Array*/

%ARRAY(REGRESSORS,VALUES=A B);

%MACRO SIMULATION;

%DO MACRO = 1 %TO 2;

/*2. Regression*/

proc reg data=panel;

model y = %DO_OVER(REGRESSORS);

run;

%end;

%MEND SIMULATION;

%SIMULATION;

run;

Since then I always get the following error message for the MACRO inside the loop:

NOTE: Line generated by the macro function "TP".

1 %&MACRO(&&REGRESSORS&I)

-

76


ERROR 22-322: Syntax error, expecting one of the following: a name, ;, /, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_, {.

ERROR 76-322: Syntax error, statement will be ignored.

Hopefully you could help me with this dilemma..... THANK YOU!!!

You have a macro SIMULATION and what appears to be PROC REG inside some kind of macro loop.  Are you doing a simulation with many iterations (models/datasets/samples) where you intend to summerize the results?  Perhaps some kind of bootstrap or other computer intensive method.  If so I suspect you will not be happy with the performance you will get macro looping over multiple call to procs and or data steps.  If you are trying to fit a bunch of different models I'm sure there are better ways, using ONE call to PROC REG.

MarkGIP
Calcite | Level 5

Thanks for the advise...

But could someone tell me what I'm doing wrong?

THANK YOU!!!

Reeza
Super User

I ran the macros from both of the files in the link above and then ran the code you provided and everything worked fine.

If i delete the do_over macro I get the errror you have, so I wonder if you didn't run both the array and do_over macro code first or if they're stored somewhere else other than your work library.

MarkGIP
Calcite | Level 5

Hi Reeza,

Hmm, that's strange... The macro code is right above the other code I posted. No clue:(

Thank you though for your effort!

Tom
Super User Tom
Super User

And what is before that?  Perhaps a comment has "eaten" your macro?

Astounding
PROC Star

MarkGIP,

The macros you are using would take a while to work through, even for the best of macro programmers.  Not having done that, I would still recommend that you add this as the first line of your macro:

%macro SIMULATION;

%local MACRO;

Then continue with the rest of the program as is.  It is conceivable that this will solve the problem.

More important is that you are just learning macros.  It is very likely you are trying to kill a fly with a sledgehammer here.  If you post what you are trying to accomplish (what do you feed into the macro, such as the list A B, and what SAS code are you hoping to generate), you will receive many posts showing you how to accomplish the task in a simple manner.

Good luck.

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!

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
  • 11 replies
  • 3316 views
  • 0 likes
  • 6 in conversation