Storing and Reusing Macros

When you submit a macro definition, by default, the macro processor compiles and stores the macro in a SAS catalog in the WORK library. These macros, referred to as session compiled macros, exist only during the current SAS session. To save frequently used macros between sessions, you can use either the autocall macro facility or the stored compiled macro facility.
The autocall macro facility stores the source for SAS macros in a collection of external files called an autocall library. The autocall facility is useful when you want to create a pool of easily maintained macros in a location that can be accessed by different applications and users. Autocall libraries can be concatenated together. The primary disadvantage of the autocall facility is that the first time an autocall macro is called in a session, the macro processor compiles it. This compilation is overhead that you can avoid by using the stored compiled macro facility.
The stored compiled macro facility stores compiled macros in a SAS catalog in a SAS library that you specify. By using stored compiled macros, you might save macro compilation time in your production-level jobs. However, because these stored macros are compiled, you must save and maintain the source for the macro definitions in a different location.
The autocall facility and the stored compiled macro facility each offer advantages. Here are some of the factors that determine how you choose to save a macro definition:
  • how often you use a macro
  • how often you change it
  • how many users need to execute it
  • how many compiled macro statements it has
If you are developing new programs, consider creating macros and compiling them during your current session. If you are running production-level jobs using name-style macros, consider using stored compiled macros. If you are letting a group of users share macros, consider using the autocall facility.
Note: For greater efficiency, store only name-style macros if you use the stored compiled macro facility. Storing statement-style and command-style macros is less efficient.
It is good practice, when you are programming stored compiled macros or autocall macros, to use the %LOCAL statement to define macro variables that will be used only inside that macro. Otherwise, values of macro variables defined outside of the current macro might be altered. See the discussion of macro variable scopes in Scopes of Macro Variables.
In general, macro and variable names in the SAS macro facility are case insensitive and are internally changed to uppercase. The values are case sensitive in the SAS macro facility and are not changed.
When calling an autocall macro or a stored compiled macro, the macro name is changed to uppercase and passed to the catalog routines to open a member of that name. The catalog routines are host dependent and use the default casing for the particular host when searching for a member. Macro catalog entries should be made using the default casing for the host in question. Here are the host defaults:
  • UNIX default is lowercase
  • z/OS default is uppercase
  • Windows default is lowercase
Note: In UNIX, the member name that contains the autocall macro must be all lowercase letters.