Getting Started with the Macro Facility

This document is the macro facility language reference for SAS. It is a reference for the SAS macro language processor and defines the SAS macro language elements. This section introduces the SAS macro facility using simple examples and explanation.
The macro facility is a tool for extending and customizing SAS and for reducing the amount of text that you must enter to do common tasks. The macro facility enables you to assign a name to character strings or groups of SAS programming statements. You can work with the names that you created rather than with the text itself.
The SAS macro language is a string based language. It does not support the use of hexadecimal character constants.
Note: The SAS macro language does not support using hexadecimal values to specify non-printable characters.
When you use a macro facility name in a SAS program or from a command prompt, the macro facility generates SAS statements and commands as needed. The rest of SAS receives those statements and uses them in the same way it uses the ones that you enter in the standard manner.
The macro facility has two components:
macro processor
is the portion of SAS that does the work
macro language
is the syntax that you use to communicate with the macro processor
When SAS compiles program text, two delimiters trigger macro processor activity:
&name
refers to a macro variable. Replacing Text Strings Using Macro Variables explains how to create a macro variable. The form &name is called a macro variable reference.
%name
refers to a macro. Generating SAS Code Using Macros explains how to create a macro. The form %name is called a macro call.
The text substitution produced by the macro processor is completed before the program text is compiled and executed. The macro facility uses statements and functions that resemble the statements and functions that you use in the DATA step. An important difference, however, is that macro language elements can enable only text substitution and are not present during program or command execution.
Note: Three SAS statements begin with a % that are not part of the macro facility. These elements are the %INCLUDE, %LIST, and %RUN statements in SAS Statements: Reference
The following graphic explains the syntax used in this document:
Syntax Conventions