Chapter 1
Introduction to the Macro Facility
Getting Started with the Macro Facility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Using the Macro Facility in SAS Viya . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Replacing Text Strings Using Macro Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Generating SAS Code Using Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Defining Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Inserting Comments in Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Macro Definition Containing Several SAS Statements . . . . . . . . . . . . . . . . . . . . . . 10
Passing Information into a Macro Using Parameters . . . . . . . . . . . . . . . . . . . . . . . . 11
Conditionally Generating SAS Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
More Advanced Macro Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Generating Repetitive Pieces of Text Using %DO Loops . . . . . . . . . . . . . . . . . . . . 12
Generating a Suffix for a Macro Variable Reference . . . . . . . . . . . . . . . . . . . . . . . . 13
Other Features of the Macro Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
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:
3
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset