Macros for SAS Application Developers
Macro Core

npm package Github Workflow npm Snyk Vulnerabilities for npm package License GitHub top language GitHub closed issues GitHub issues total lines Gitpod ready-to-code

Much quality. Many standards. The Macro Core library exists to save time and development effort! Herein ye shall find a veritable host of MIT-licenced, production quality SAS macros. These are a mix of tools, utilities, functions and code generators that are useful in the context of Application Development on the SAS platform (eg Contributions are welcomed.

You can download and compile them all in just two lines of SAS code:

filename mc url "";
%inc mc;



BASE library (SAS9/Viya)

  • OS independent
  • Not metadata aware
  • No X command
  • Prefixes: mf, mp

FCMP library (SAS9/Viya)

  • Function and macro names are identical, except for special cases
  • Prefixes: mcf

The fcmp macros are used to generate fcmp functions, and can be used with or without the proc fcmp wrapper.

META library (SAS9 only)

Macros used in SAS EBI, which connect to the metadata server.

  • OS independent
  • Metadata aware
  • No X command
  • Prefixes: mm

SERVER library (@sasjs/server only)

These macros are used for building applications using @sasjs/server - an open source REST API for Desktop SAS.

  • OS independent
  • @sasjs/server aware
  • No X command
  • Prefixes: ms

VIYA library (Viya only)

Macros used for interfacing with SAS Viya.

  • OS independent
  • No X command
  • Prefixes: mv, mvf

METAX library (SAS9 only)

  • OS specific
  • Metadata aware
  • X command enabled
  • Prefixes: mmw,mmu,mmx

LUA library

Wait - this is a macro library - what is LUA doing here? Well, it is a little known fact that you CAN run LUA within a SAS Macro. It has to be written to a text file with a .lua extension, from where you can include it. So, without using the proc lua wrapper.

To contribute, simply write your freeform LUA in the LUA folder. Then run the, which will convert your LUA into a data step with put statements, and create the macro wrapper with a ml_ prefix. You can then use your module in any program by running:

/* compile the lua module */
/* Execute. Do not use the restart keyword! */
proc lua;
  • X command enabled
  • Prefixes: mmw,mmu,mmx


First, download the repo to a location your SAS system can access. Then update your sasautos path to include the components you wish to have available, eg:

options insert=(sasautos="/your/path/macrocore/base");
options insert=(sasautos="/your/path/macrocore/meta");

The above can be done directly in your sas program, via an autoexec, or an initialisation program.

Alternatively - for quick access - simply run the following! This file contains all the macros.

filename mc url "";
%inc mc;


File Properties

  • filenames much match macro names
  • filenames must be lowercase, without spaces
  • macro names must be lowercase
  • one macro per file
  • prefixes:
    • mcf for macro compiled functions (proc fcmp)
    • mf for macro functions (can be used in open code).
    • ml for macros that are used to compile LUA modules
    • mm for metadata macros (interface with the metadata server).
    • mmx for macros that use metadata and are XCMD enabled
    • mp for macro procedures (which generate sas code)
    • ms for macro procedures that will only work with @sasjs/server
    • mv for macro procedures that will only work in Viya
    • mx for macros that are XCMD enabled
  • follow verb-noun convention
  • unix style line endings (lf)
  • individual lines should be no more than 80 characters long
  • UTF-8

Header Properties

The Macro Core documentation is created using doxygen. A full list of attributes can be found here but the following are most relevant:

  • file. This needs to be present in order to be recognised by doxygen.
  • brief. This is a short (one sentence) description of the macro.
  • details. A longer description, which can contain doxygen markdown.
  • param. Name of each input param followed by a description.
  • return. Explanation of what is returned by the macro.
  • version. The EARLIEST SAS version in which this macro is known to work.
  • author. Author name, contact details optional

All macros must be commented in the doxygen format, to enable the online documentation.


SAS code can contain one of two types of dependency - SAS Macros, and SAS Includes. When compiling projects using the SASjs CLI the doxygen header is scanned for @li items under the following headers:

<h4> SAS Macros </h4>
<h4> SAS Includes </h4>
@li somefile.ddl SOMEFREF

The CLI can then extract all the dependencies and insert as precode (SAS Macros) or in a temp engine fileref (SAS Includes) when creating SAS Jobs and Services (and Tests).

When contributing to this library, it is therefore important to ensure that all dependencies are listed in the header in this format.

Coding Standards

  • Indentation = 2 spaces. No tabs!
  • no trailing white space
  • no invisible characters, other than spaces. If invisibles are needed, use hex literals.
  • Macro variables should not have the trailing dot (&var not &var.) unless necessary to prevent incorrect resolution
  • The closing mend; should not contain the macro name.
  • All macros should be defined with brackets, even if no variables are needed - ie macro x(); not macro x;
  • Mandatory parameters should be positional, all optional parameters should be keyword (var=) style.
  • All dataset references must be 2 level (eg work.blah, not blah). This is to avoid contention when options DATASTMTCHK=ALLKEYWORDS is in effect.
  • Avoid naming collisions! All macro variables should be local scope. Use system generated work tables where possible - eg data ; set sashelp.class; run; data &output; set &syslast; run;
  • Where global macro variables are absolutely necessary, they should make use of &sasjs_prefix - see
  • The use of quit; for proc sql is optional unless you are looking to benefit from the timing statistics.
  • Use sasjs lint!

General Notes

  • All macros should be compatible with SAS versions from support level B and above (so currently 9.2 and later). If an earlier version is not supported, then the macro should say as such in the header documentation, and exit gracefully (eg if sysevalf(&sysver<9.3) then return).

Breaking Changes

We are currently on major release v4. Breaking changes should be marked with the deprecated doxygen tag. The following changes are planned when the next major (breaking) release becomes necessary:

  • (None as yet)

Star Gazing

If you find this library useful, please leave a star and help us grow our star graph!

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

Allan Bowe

💼 💻 🖋 📖 🚇 🚧 🧑‍🏫 💬 👀 ⚠️



Trevor Moody


Krishna Acondy

💻 🚇 📝 🖋 🤔 📹

Muhammad Saad

💻 🤔

Yury Shkoda

💻 🚇 📹

Mihajlo Medjedovic




Vladislav Parhomchik

⚠️ 👀

Vignesh T.


This project follows the all-contributors specification. Contributions of any kind welcome!