Macros allow to write a program that writes another (or more) programs (sometimes referred to as meta programming)
Usually, the goal is to write macro statements that the macro processor turns into standard SAS statements.
Macros are especially useful to create variations of repetitive code.
Macro statements start with a percent sign (%). A defined macro is evaluated by also prepending its name with a percent sign.
Define macro
%macro macro_name [(parameters)]
macro text
%mend macro_name;
This macro is then invoked like so:
%macro_name
and evalulates to macro text.
Compilation of a macro
The compilation of a macro creates two things:
compiled macro statements
text
Comments
Preferrably, comments in macros should be of the form % comment text etc... ; except when commenting macro parameters in which case /* .... */ should be used.
Autocall libraries
Macros should be stored in SAS autocall libraries in order for them to be in a standard location.
On Unix and Windows, an autocall library is a (filesystem-)directory that stores macros.
Macros in an autocall library are not compiled. If not protected, their source can be looked at.
In contrast, the stored compiled macro library does not necessarily have the source code with it.