how often you change it
how many users need to execute it
how many compiled macro statements it has
If you are developing new programs, consider creating macros and compiling them
during your current session. If you are running production-level jobs using name-style
macros, consider using stored compiled macros. If you are letting a group of users share
macros, consider using the autocall facility.
Note: For greater efficiency, store only name-style macros if you use the stored
compiled macro facility. Storing statement-style and command-style macros is less
efficient.
It is good practice, when you are programming stored compiled macros or autocall
macros, to use the %LOCAL statement. This statement defines macro variables that will
be used only inside that macro. Otherwise, values of macro variables defined outside of
the current macro might be altered. See the discussion of macro variable scopes in
Chapter 5, “Scopes of Macro Variables,” on page 49.
In general, macro and variable names in the SAS macro facility are case insensitive and
are internally changed to uppercase. The values are case sensitive in the SAS macro
facility and are not changed.
When calling an autocall macro or a stored compiled macro, the macro name is changed
to uppercase and passed to the catalog routines to open a member of that name. The
catalog routines are host dependent and use the default casing for the particular host
when searching for a member. Macro catalog entries should be made using the default
casing for the host in question. Here are the host defaults:
UNIX default is lowercase
z/OS default is uppercase
Windows default is lowercase
Note: In UNIX, the member name that contains the autocall macro must be all
lowercase letters.
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.
116 Chapter 9 Storing and Reusing Macros
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 that 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.
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 more information, see your host documentation and “SASAUTOS=
System Option” on page 382.
When storing files in an autocall library, remember the following:
SAS does not restrict the type of material that you place in an autocall library. You
should store only autocall library files in it to avoid confusion and for ease of
maintenance.
SAS lets you include more than one macro definition, as well as open code, in an
autocall library member. You should generally keep only one macro in any autocall
library member. If you need to keep several macros in the same autocall library
member, keep related macros together.
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-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” on page 382.
Saving Macros in an Autocall Library 117
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” on page 359 and “SASAUTOS= System Option”
on page 382.
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:
searches for a session compiled macro definition
searches for a stored compiled macro definition in the library specified by the
SASMSTORE option, if the MSTORED option is set
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
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:
compiles all of the source statements in that member, including any and all macro
definitions, and stores the result in the session catalog
executes any open code (macro statements or SAS source statements not within any
macro definition) in that member
executes the macro with the name that 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 that you
invoked.
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. SAS 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,” on page 121.
118 Chapter 9 Storing and Reusing Macros
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset