Monday, 3 April 2017

SAS: BUILDING SAS MACRO LIBRARY

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;

No comments:

Post a Comment