Professional Documents
Culture Documents
Text Version
Creating a Stored Compiled Macro
The stored compiled macro facility stores compiled macros in permanent SAS catalogs. There is no
need to recompile macro source code. This saves compilation time, which can be substantial for large
programs.
When you use the stored compiled macro facility, macro source code can be protected or hidden. To
enable macro storage using the stored compiled macro facility, you use the MSTORED and
SASMSTORE= system options. The MSTORED option enables the stored compiled macro facility,
and the SASMSTORE= option indicates where the macro is permanently stored. Notice that the
SASMSTORE libref cannot be work. The SASMSTORE= option designates a single library. To
include multiple libraries, concatenate the libraries.
You store a permanent compiled macro using options in the %MACRO statement. The options are
STORE, SOURCE, SECURE, and DES='text'.
The STORE option is required in order to store the compiled macro. This option stores the compiled
macro as a catalog entry in the library indicated by the SASMSTORE= system option.
The SOURCE option stores the macro source code with the compiled code. Use this if you want to
insure that your source code matches the compiled code. If the source is stored with the compiled
code, you can use the %COPY statement to retrieve the source into the log or a file.
The SECURE option encrypts the stored compiled macro and disables the %COPY statement and the
SYMBOLGEN, MLOGIC, and MPRINT options. This protects the code from being viewed or changed
in any way.
The DES='text' option specifies a description of the macro catalog entry, which can be helpful in
identifying the macro and its functionality.
This macro uses the STORE and SOURCE options, so the compiled macro is stored in a catalog
named SASMACR in the location specified in the SASMSTORE= system option with the macro
source code. When a macro is compiled and stored in a permanent library, a lock is placed on the
SASMSTORE=libref for the remainder of that session. Therefore the libref cannot be cleared or
reassigned while the lock remains in place. To close the stored compiled macro catalog, as well as to
release the lock and clear the libref, use the %SYSMSTORECLEAR statement.
Copyright 2015 SAS Institute Inc., Cary, NC, USA. All rights reserved.
Text Version
Expand Print
Although compiled code cannot be edited, the source code can be changed and the macro then
recompiled. You learned that the SOURCE option stores the macro source code with the permanent
compiled macro. To retrieve source code saved with the SOURCE option, you use the %COPY
statement with the SOURCE option.
Start with %COPY followed by the macro name and then a forward slash. After the slash you include
options such as LIBRARY= and OUT=, as well as the SOURCE keyword option. These options can
be placed on this statement in any order. End the statement with a semicolon.
Let's take a look at the options. You use the LIBRARY= option to specify a SAS library that contains a
catalog of stored compiled SAS macros. If no library is specified, the libref specified by the
SASMSTORE= option is used. The OUT= option specifies the output destination of the %COPY
statement. The value can be a fileref or an external file. If OUT= is omitted, the source code is written
to the SAS log.
Here is the code to copy the source code for the Calc macro to the SAS log. Because there is no
OUT= option, the source code is copied to the log.
Remember that if the SECURE option is used while storing the macro, the contents of the macro are
encrypted. If you use the SECURE and SOURCE options on a macro, no output is produced when
you use the %COPY statement, and a note appears in the log.
Copyright 2015 SAS Institute Inc., Cary, NC, USA. All rights reserved.
Text Version
Expand Print
Copyright 2015 SAS Institute Inc., Cary, NC, USA. All rights reserved.
Text Version
Expand Print
Remember, if an autocall library macro was previously referenced and compiled during the session
and you want to repeat a search of the macro, you must delete the macro from
the work.sasmacr catalog first.
Copyright 2015 SAS Institute Inc., Cary, NC, USA. All rights reserved.