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(&®RESSORS&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!!!
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 = ®ressors ;
run;
%MEND SIMULATION;
%SIMULATION(panel,A B);
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?
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.
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...
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
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(&®RESSORS&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.
Thanks for the advise...
But could someone tell me what I'm doing wrong?
THANK YOU!!!
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.
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!
And what is before that? Perhaps a comment has "eaten" your macro?
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.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: