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

JT. picture JT. · Feb 11, 2009 · Viewed 28.6k times · Source

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!

Answer

AFHood picture AFHood · Feb 11, 2009

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;