CISER header image
Cornell University Cornell University CISER

CISER Secure Data Services:  CRADC

If you have a number of files containing SAS macro definitions, you can access these macros in your SAS session by using one of two methods. The %INCLUDE statement in SAS allows you to access SAS code stored in an external text file. The SAS system option SASAUTOS allows you to access all macro definitions in your autocall macro libraries. An autocall macro library contains files that define SAS macros.

Here are two ways to access user defined macros in a SAS session:

I. Modify SASAUTOS System Option:

When the SAS system is installed, the SASAUTOS option is used in the SAS configuration file to tell the SAS system where to find the default macros supplied by the Institute. You can also define your own autocall macros and access them within your SAS session. In a Windows directory, the macro file extension must be .SAS, and each macro file must contain a macro definition with a macro name the same as the filename.

To use your own autocall macros in your SAS programs, you must tell the SAS System where to find them using the SASAUTOS option. The SASAUTOS option can be modified in your SAS configuration file to include your autocall macros, it can be included in an OPTIONS statement during your SAS session, or it can be part of the command that invokes your SAS session. (Note: When a SAS System Option is set in more than one place, the Options window or OPTIONS statement takes precedence over the SAS autoexec file; the SAS autoexec file takes precedence over the SAS command; and the SAS command takes precedence over the SAS configuration file.)

Syntax for the SASAUTOS option:

-SASAUTOS(library_specification_1 library_specification_2 ... library_specification_n)
                                  or
SASAUTOS("library_specification_1" " library_specification_2" ... "library_specification_n")

  1. SASAUTOS option in SAS Configuration File:

    The SASAUTOS system option in the SAS Configuration file specifies the autocall macro libraries available to the SAS system. The default setup specifies autocall macro libraries supplied by the SAS Institute. To concatenate your autocall libraries to the list provided by SAS, create a copy of the SAS configuration file (“C:\Program Files\SAS Institute\SAS\V8\SASV8.CFG”) in your authorized folder on CRADC file server R:\. Modify your copy of the .CFG file to include your autocall libraries in -SET SASAUTOS (Scroll down to the section where it says “DO NOT EDIT BELOW THIS LINE…”, below that you'll see a comment "Setup the SAS System autocall library definition", concatenate your libraries to that list). Now if you want the SAS to use your configuration file to set the defaults, on each CRADC server, modify the Properties of your SAS shortcut to substitute your configuration file in the Target field.

    Here is an example of concatenating autocall macro library "R:\Development\sas_macros" with the default SAS autocall libraries in your SAS configuration file:

          /* Setup the SAS System autocall library definition */

          -SET SASAUTOS ( "R:\Development\sas_macros"
                "!sasroot\core\sasmacro"
                "!sasext0\dmine\sasmacro"
                "!sasext0\access\sasmacro"
                "!sasext0\assist\sasmacro"
                "!sasext0\eis\sasmacro"
                "!sasext0\ets\sasmacro"
                "!sasext0\gis\sasmacro"
                "!sasext0\graph\sasmacro"
                "!sasext0\or\sasmacro"
                "!sasext0\qc\sasmacro"
                "!sasext0\share\sasmacro"
                "!sasext0\stat\sasmacro"
                  )


    When SAS Searches for an autocall macro definition, it opens and searches each location in the same order that it is specified in the SASAUTOS option. Therefore, to make a SAS search more efficient, put your autocall macro library before the other SAS Institute default autocall libraries.
  2. SASAUTOS in an OPTIONS Statement in a SAS Session:

    The SASAUTOS option can be included in the OPTIONS Statement in a SAS session. The options specified in an OPTIONS Statement in a SAS program override the defaults set by the SAS system. Therefore, in an OPTIONS statement it is important to concatenate the autocall libraries supplied by the SAS Institute with your autocall library so that the SAS macros will also be available.

    Here is an example of accessing a macro autocall library "R:\Development\sas_macros" using an OPTIONS statement in a SAS session:

          OPTIONS SASAUTOS= ( "R:\Development\sas_macros"
                "!sasroot\core\sasmacro"
                "!sasext0\dmine\sasmacro"
                "!sasext0\access\sasmacro"
                "!sasext0\assist\sasmacro"
                "!sasext0\eis\sasmacro"
                "!sasext0\ets\sasmacro"
                "!sasext0\gis\sasmacro"
                "!sasext0\graph\sasmacro"
                "!sasext0\or\sasmacro"
                "!sasext0\qc\sasmacro"
                "!sasext0\share\sasmacro"
                "!sasext0\stat\sasmacro"
                  ) ;


    Note: Autocall Libraries are searched in the order you specify them. 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.
  3. SASAUTOS option in the SAS Invocation:

    You can also specify the SASAUTOS option at initialization. The option must be preceded by a hyphen (-) and there should be a space between the option and it's values.

    For example the following command invokes the SAS System with the SAS output line size of 125, and autocall library:

    R:\Development\sas_macros (Note: Now SAS system autocall libraries will not be available).

    C:\Program Files\SAS Institute\SAS\V8\SAS.EXE -linesize 125 -sasautos "R:\Development\sas_macros"

 

II. Use the %Include Statement in a SAS Session:

Use %INCLUDE statement to call an external file containing macro definitions in your SAS session. When you execute a %INCLUDE statement, SAS executes the statements that you bring into the session with %INCLUDE.

Syntax:

%include filename ; /* Substitute appropriate filename */

Here is an example of %include statements in a SAS session:

%INCLUDE "R:\Development\sas_macros\clogit.sas" ;
%INCLUDE "R:\Development\sas_macros\logitmask.sas" ;
%INCLUDE "R:\Development\sas_macros\mlogitmask.sas" ;