
Saving Macros Using the Stored Compiled Macro
Facility
Overview of the Stored Compiled Macro Facility
The stored compiled macro facility compiles and saves compiled macros in a permanent
catalog in a library that you specify. This compilation occurs only once. If the stored
compiled macro is called in the current or later sessions, the macro processor executes
the compiled code.
In SAS 9.1.3 or higher, the stored compiled macro catalog is initially opened for Read-
Only access. When a stored compiled macro is being compiled or updated, the catalog is
immediately closed and reopened for Update access. After the macro is compiled and the
catalog has been updated or changed, the catalog is again immediately closed and
reopened for Read-Only access.
Compiling and Storing a Macro Definition
To compile a macro definition in a permanent catalog, you must first create the source
for each stored compiled macro. To store the compiled macro, use the following steps:
1. Use the STORE option in the %MACRO statement. You can use the SOURCE
option to store the source code with the compiled code. In addition, you can assign a
descriptive title for the macro entry in the SAS catalog, by specifying the DES=
option. For example, the %MACRO statement in the following definition shows the
STORE, SOURCE, and DES= options:
%macro myfiles / store source
des='Define filenames';
filename file1 'external-file-1';
filename file2 'external-file-2';
%mend;
CAUTION:
Save your macro source code. You cannot re-create the source statements from
a compiled macro. Therefore, you must save the original macro source
statements if you want to change the macro. For all stored compiled macros, you
should document your macro source code well. You can save the source code
with the compiled code using the SOURCE option in the %MACRO statement or
you can save the source in a separate file. If you save the source in a separate file,
it is recommended that you save the source code in the same catalog as the
compiled macro. In this example, save it to the following library:
mylib.sasmacro.myfiles.source
Note: To retrieve the source of a compiled stored macro, see “%COPY Statement”
on page 300.
2. Set the MSTORED system option to enable the stored compiled macro facility. For
more information, see “MSTORED System Option” on page 369.
Saving Macros Using the Stored Compiled Macro Facility 117