Previous Page | Next Page

Storing and Reusing Macros

Saving Macros in an Autocall Library


Overview of an Autocall Library

Generally, an autocall library is a directory containing individual files, each of which contains one macro definition. In SAS 6.11 and later, an autocall library can also be a SAS catalog. (See the following section for more information about using SAS catalogs as autocall libraries.)

Operating Environment Information:   Autocall Libraries on Different Hosts The term directory refers to an aggregate storage location that contains files (or members) managed by the host operating system. Different host operating systems identify an aggregate storage location with different names, such as a directory, a subdirectory, a maclib, a text library, or a partitioned data set. For more information, see the SAS Companion for your operating system.   [cautionend]


Using Directories as Autocall Libraries

To use a directory as a SAS autocall library, do the following:

  1. To create library members, store the source code for each macro in a separate file in a directory. The name of the file must be the same as the macro name. For example, the statements defining a macro you would call by submitting %SPLIT must be in a file named SPLIT.

    Operating Environment Information:   Autocall Library Member Names On operating systems that allow filenames with extensions, you must name autocall macro library members with a special extension, usually .SAS . Look at the autocall macros on your system provided by SAS to determine whether names of files containing macros must have a special extension at your site.

    On z/OS operating systems, you must assign the macro name as the name of the PDS member.  [cautionend]

  2. Set the SASAUTOS system option to specify the directory as an autocall library. On most hosts, the reserved fileref SASAUTOS is assigned at invocation time to the autocall library supplied by SAS or another one designated by your site. If you are specifying one or more autocall libraries, remember to concatenate the autocall library supplied by SAS with your autocall libraries so that these macros will also be available. For details, refer to your host documentation and SASAUTOS= System Option.

When storing files in an autocall library, remember the following:


Using SAS Catalogs as Autocall Libraries

In SAS 6.11 and later, you can use the CATALOG access method to store autocall macros as SOURCE entries in SAS catalogs. To create an autocall library using a SAS catalog, follow these steps:

  1. Use a LIBNAME statement to assign a libref to the SAS library.

  2. Use a FILENAME statement with the CATALOG argument to assign a fileref to the catalog that contains the autocall macros. For example, the following code creates a fileref, MYMACROS, that points to a catalog named MYMACS.MYAUTOS:

    libname mymacs 'SAS-data-library';
    filename mymacros catalog 'mymacs.myautos';

  3. Store the source code for each macro in a SOURCE entry in a SAS catalog. (SOURCE is the entry type.) The name of the SOURCE entry must be the same as the macro name.

  4. Set the SASAUTOS system option to specify the fileref as an autocall library. For more information, see SASAUTOS= System Option.


Calling an Autocall Macro

To call an autocall macro, the system options MAUTOSOURCE must be set and SASAUTOS must be assigned. MAUTOSOURCE enables the autocall facility, and SASAUTOS specifies the autocall libraries. For more information, see MAUTOSOURCE System Option and SASAUTOS= System Option.

Once you have set the required options, calling an autocall macro is like calling a macro that you have created in your current session. However, it is important that you understand how the macro processor locates the called macro. When you call a macro, the macro processor does the following tasks:

  1. searches for a session compiled macro definition

  2. searches for a stored compiled macro definition in the library specified by the SASMSTORE option, if the MSTORED option is set

  3. searches for a member in the autocall libraries specified by the SASAUTOS option in the order in which they are specified, if the MAUTOSOURCE option is set

  4. searches the SASHELP library for SAS production stored compiled macro definitions

When SAS finds a library member in an autocall library with that macro name, the macro processor does the following:
  1. compiles all of the source statements in that member, including any and all macro definitions, and stores the result in the session catalog.

  2. executes any open code (macro statements or SAS source statements not within any macro definition) in that member.

  3. executes the macro with the name you invoked

Note:   If an autocall library member contains more than one macro, the macro processor compiles all of the macros but executes only the macro with the name you invoked  [cautionend]

Any open code statements in the same autocall library member as a macro execute only the first time you invoke the macro. When you invoke the macro later in the same session, the compiled macro is executed, which contains only the compiled macro definition and not the other code the autocall macro source file might have contained.

It is not advisable to change SASAUTOS during a SAS session. If you change the SASAUTOS= specification in an ongoing SAS session, SAS will store the new specification only until you invoke an uncompiled autocall macro and then will close all opened libraries and open all the newly specified libraries that it can open.

For information about debugging autocall macros, see Macro Facility Error Messages and Debugging.

Previous Page | Next Page | Top of Page