In my code I have several macros. Macro A is the main macro. Macro A then calls macro B which in turn calls macro C.
In SAS, do I have to define them in backwards order? In other words, do I have to define macro C first, then macro B, then macro A last? Or does it matter since SAS reads all the code in before it actually hits the command to run the macros? For that matter, can I issue the command to run the macro as the first statement in my code and then define the macros below the command?
Thanks!
First, you must define a macro before it is called.
Second, it doesn't matter where the macro is invoked as long as you have loaded it before-hand.
To elaborate on your issue: The autocall library is your friend. If you SAS administrator won't allow you to put your macros in the autocall library, you can append the autocall like so:
filename mymacros 'c:\mysas';
/*this defines the directory you have stored your macros*/
options sasautos=(sasautos mymacros) mautosource;
a macro has to be defined before it is called. for performance reasons, it is best not to define a macro inside another -- if you do so, then it will be re-defined every time you call the outer macro. the following works fine:
%macro a;
%put a;
%b
%mend a;
%macro b;
%put b;
%c
%mend b;
%macro c;
%put c;
%mend c;
%*-- %a is main --*;
%a
/* on log
a
b
c
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With