Building SAS Macro Library

Deepanshu Bhalla 6 Comments

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
1. % 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.

2. AUTOCALL Macro Facility

The name of the file must be the same as the macro name. For eg. the file that contains '%storemacroval' macro must be named as 'storemacroval.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.

3. 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;
How to see list of all stored macros
libname loct "C:\Users\Deepanshu\Downloads\";
PROC CATALOG catalog=loct.sasmacr;
Contents;
Run;
How to see list of all compiled macros
proc sql;
select * from dictionary.catalogs where memname in ('sasmacr');
quit;
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 6 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
  3. Hi Deepanshu,
    Thanks for writing on SAS Macro library.
    Could you please also try to explain more on the usage of sas macro library.
    e.g. in what situation it is ideal to use sas macro library rather then writing sas macros within the code itself.

    Thanks.

    ReplyDelete
  4. Could you explain about the cdisc,sdtm,adam like above questions

    ReplyDelete
Next → ← Prev