Building SAS Macro Library

This tutorial explains how to store macros in a location and call them from the location.

3 Types of Macro Library
  1. % Include
  2. Autocall Macro Facility
  3. Stored Compiled Macro

I. % INCLUDE
Store macros in a location and call it from the location using %Include.
%include "C:\Users\Deepanshu\Downloads\storemacroval.sas";%storemacroval;
In the program above, the directory contains macro and %storemacroval is a name of macro.

Disadvantage : You have to mention file name of the macros.

II. AUTOCALL Macro Facility
The name of the file must be the same as the macro name. For eg. The name of the file where in %temp macro placed can only be temp.sas. On the UNIX OS, the name of the file that stores the macro definition must be in all lowercase characters.
options mautolocdisplay mautosource sasautos = ("C:\Users\Deepanshu\Downloads\") ;
%storemacroval;
In the program above, the directory contains individual files. Each file contains one macro definition.

III. Stored Compiled Macro Facility

Step I : Storing the macro

In the macro code, add the following lines.
libname loct "C:\Users\Deepanshu\Downloads\";
options mstored sasmstore = loct;
%macro storemacroval / store source des="Description of Macro";
Step II : Using Stored Compiled Macros
libname loct "C:\Users\Deepanshu\Downloads\";
options mstored sasmstore = loct;
%storemacroval;
See the list of all the macros stored
libname loct "C:\Users\Deepanshu\Downloads\";
PROC CATALOG catalog=loct.sasmacr;
Contents;
Run;
See the list of all the macros compiled
proc sql;
select * from
dictionary.catalogs where memname in ('sasmacr');
quit;
Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

4 Responses to "Building SAS Macro Library"

  1. I was thinking from yesterday if you could post something about autocall sas macro and Its miracle today you posted it/

    ReplyDelete
  2. Can you recommend some good books for Statistics in SAS or R language ?

    ReplyDelete

Next → ← Prev