Using the Macro Facility

A macro is a set of commands that generates customized command syntax. Using macros can reduce the time and effort needed to perform complex and repetitive data analysis tasks.

Macros have two parts: a macro definition, which indicates the beginning and end of the macro and gives a name to the macro, and a macro body, which contains regular commands or macro commands that build command syntax. When a macro is invoked by the macro call, syntax is generated in a process called macro expansion. Then the generated syntax is executed as part of the normal command sequence.

This chapter shows how to construct macros that perform three data analysis tasks. In the first example, macros facilitate a file-matching task. In Example 2, macros automate a specialized statistical operation (testing a sample correlation coefficient against a nonzero population correlation coefficient). Macros in Example 3 generate random data. As shown in the following table, each example demonstrates various features of the macro facility. For information on specific macro commands, see the DEFINE command.

Table 1. Macro features
  Example 1 Example 2 Example 3
Macro argument      
Keyword x x x
Default values x   x
None x   x
String manipulation x   x
Looping      
Index x   x
List processing   x  
Direct assignment x   x