Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS: Calling one macro from another...Order of Macro Definitions

Tags:

sas

sas-macro

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!

like image 353
JT. Avatar asked Feb 11 '09 15:02

JT.


2 Answers

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; 
like image 67
AFHood Avatar answered Oct 09 '22 17:10

AFHood


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
*/
like image 29
Chang Chung Avatar answered Oct 09 '22 16:10

Chang Chung