Chapter Contents

Previous

Next
SAS Macro Language: Reference

Saving Macros in an Autocall Library

Generally, an autocall library is a directory containing individual files, each of which contains one macro definition. In Release 6.11 or later, an autocall library can also be a SAS catalog (see "Using SAS Catalogs as Autocall Libraries" below).

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 Institute to determine whether names of files containing macros must have a special extension at your site.

    On MVS 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 Institute or another one designated by your site. If you are specifying one or more autocall libraries, remember to concatenate the autocall library supplied by the Institute with your autocall libraries so that these macros will also be available. For details, refer to your host documentation and SASAUTOS in Chapter 13, "Macro Language Dictionary."

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


Using SAS Catalogs as Autocall Libraries

In Release 6.11 or 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 in Chapter 13.


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 on these options, see MAUTOSOURCE and SASAUTOS in Chapter 13.

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 searches first for a session compiled macro definition. Next, the macro processor searches for a permanently stored compiled macro. If compiled stored macros are enabled with the MSTORED option, the macro processor opens the macro catalog in the library specified in the SASMSTORE option. If the macro processor does not find a compiled macro, and if MAUTOSOURCE is set, the macro processor opens libraries specified by the SASAUTOS option in the order in which they are specified in the option. It then searches each library for a member with the same name as the macro you invoked. When SAS finds a library member with that 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 within it 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 may have contained.

It is not advisable to change SASAUTOS during a SAS session. If you change the SASAUTOS= specification in an ongoing SAS session, the SAS System 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 Chapter 10, "Macro Facility Error Messages and Debugging."


Chapter Contents

Previous

Next

Top of Page

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