Chapter Contents

Previous

Next
SAS Macro Language: Reference

Saving Macros Using 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.


Compiling and Storing a Macro Definition

To compile a macro definition in a permanent catalog, create and save the source for each stored compiled macro. To store the compiled macro, follow these steps:

  1. Use the STORE option in the %MACRO statement. Optionally, 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 and DES= options:
    %macro myfiles / store
         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 and save it. It is recommended that you save the source code in the same catalog as the compiled macro. In this example, save it to
    mylib.sasmacro.myfiles.source
      [cautionend]

  2. Set the MSTORED system option to enable the stored compiled macro facility. For more information, see MSTORED in Chapter 13.

  3. Assign the SASMSTORE option to specify the SAS data library that contains or will contain the catalog of stored compiled SAS macros. For example, to store or call compiled macros in a SAS catalog named MYLIB.SASMACR, submit these statements.
    libname mylib 'SAS-data-library';
    options mstored sasmstore=mylib;
    For more information, see SASMSTORE in Chapter 13.

  4. Submit the source for each macro that you want to compile and permanently store.

You cannot move a stored compiled macro to another operating system. You can, however, move the macro source code to another operating system where you can then compile and store it. You may need to recompile these macros if you use them in a different release of the SAS System. For more information, see your host companion.

Storing Autocall Macros Supplied by SAS Institute

If you use the macros in the autocall library supplied by SAS Institute, you can save macro compile time by compiling and storing those macros in addition to ones you create yourself. Many of the macros related to base SAS software that are in the autocall library supplied by the Institute can be compiled and stored in a SAS catalog named SASMACR by using the autocall macro COMPSTOR that is supplied by SAS Institute. For more information, see COMPSTOR in Chapter 13.


Calling a Stored Compiled Macro

Once you have set the required system options, calling a stored compiled macro is just like calling session compiled macros. However, it is important that you understand how the macro processor locates a macro. When you call a macro, the macro processor searches for the macro name using this sequence:

  1. the macros compiled during the current session

  2. the stored compiled macros in the SASMACR catalog in the specified library (if options MSTORED and SASMSTORE= are in effect)

  3. each autocall library specified in the SASAUTOS option (if options SASAUTOS= and MAUTOSOURCE are in effect).

You can display the entries in a catalog containing compiled macros. For more information, see Chapter 10.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.