Chapter 3
Macro Variables
Macro Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Macro Variables Defined by the Macro Processor . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Macro Variables Defined by Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Overview for Defining Macro Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Creating User-Defined Macro Variable Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Assigning Values to Macro Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Using Macro Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Macro Variable Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Combining Macro Variable References with Text . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Delimiting Macro Variable Names within Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Creating a Period to Follow Resolved Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Displaying Macro Variable Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Referencing Macro Variables Indirectly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Using an Expression to Generate a Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Generating a Series of Macro Variable References with a Single Macro Call . . . . . 36
Using More Than Two Ampersands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Manipulating Macro Variable Values with Macro Functions . . . . . . . . . . . . . . . . . 37
Macro Variables
Macro variables are tools that enable you to dynamically modify the text in a SAS
program through symbolic substitution. You can assign large or small amounts of text to
macro variables, and after that, you can use that text by simply referencing the variable
that contains it.
Macro variable values have a maximum length of 65,534 characters. The length of a
macro variable is determined by the text assigned to it instead of a specific length
declaration. So its length varies with each value that it contains. Macro variables contain
only character data. However, the macro facility has features that enable a variable to be
evaluated as a number when it contains character data that can be interpreted as a
number. The value of a macro variable remains constant until it is specifically changed.
Macro variables are independent of SAS data set variables.
Note: Only printable characters should be assigned to macro variables. Non-printable
values that are assigned to macro variables can cause unpredictable results.
23
..................Content has been hidden....................

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