10-19-2017 05:56 AM
I get an issue on macrovariable.inside another one.
I call a macro function A like this:
%A (mymacrovariable = MMV); %put &MMV.;
My macro function A is something like this:
%macro A (mymacrovariable); %global &mymacrovariable.; &&mymacrovariable. = 0; %mend;
When I run it I have an issue on MMV...
MLOGIC(A): Beginning execution. MLOGIC(A): Parameter MYMACROVARIABLE has value MMV MLOGIC(A): %GLOBAL &MYMACROVARIABLE. MPRINT(A): MMV = 0; MLOGIC(A): Ending execution. NOTE: Line generated by the macro variable "MYMACROVARIABLE". 31 MMV ___ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 32 %put &MMV.; 33 34 GOPTIONS NOACCESSIBLE; 35 %LET _CLIENTTASKLABEL=; 36 %LET _CLIENTPROCESSFLOWNAME=; 37 %LET _CLIENTPROJECTPATH=; 38 %LET _CLIENTPROJECTNAME=; 39 %LET _SASPROGRAMFILE=; 40 41 ;*';*";*/;quit;run; 42 ODS _ALL_ CLOSE; 43 44 2 The SAS System 11:18 Thursday, October 19, 2017 45 QUIT; RUN; 46
Can you help me to solve it?
10-19-2017 06:08 AM
&&mymacrovariable. = 0;
Generates a Base SAS statement:
Which is not in a datastep, thus error.
But seriously, why? You are hitting every bad programming practice there, creating global variables in macros, passing references to macro variables etc. There is never a need to goto this level. Base SAS is the programming language, Macro is an additional component - never needed - to help create generic code. All it does is create some text, nothing more, it is not a replacement for Base SAS. As simple example, if you find you passing data across multiple items, just put them in a dataset and use simple datastep to process things. You will find your code becomes simpler, and more robust.
10-19-2017 06:19 AM
Thanks for the answer.
But seriously, why?
I didn't want to write the complete code here. It is just the part of the code interesting here. There are also other parameters inside the macro function. The variable won't be always 0.
Moreover I create some other variables using the same macro function (and using different values for parameters of the macro function).
Instead of writing several time the same datastep for several macrovariables, it is much readable and better practises to write the code only once, I am sure
10-19-2017 06:34 AM
Without seeing the code I can't say specifically, however I would almost never see a need for multiple macro variables, references to them being passed into macro functions, and global macro variables being created within separate macro functions. You will get problems later on. A good tip is to write the code once as Base SAS, then if there are some repetitons, extract that part of the code and create macros from it. Essentially, what you are doing with macro is writing Base SAS code, but just doing it in a very complicated way.
Need further help from the community? Please ask a new question.