Improving Program Efficiency with Macro Variables |
Creating Your Own Macro
Variables |
This section teaches you how to create and use your own macro variables.
By the end of the section, you will be able to
Automatic macro variables enable you to substitute a variety of information in your programs. However, there may be times when you need to include information in programs that automatic macro variables cannot supply, such as a specific text string or the value of a data set variable. You need to create your own macro variables to supply this type of information. User-defined macro variables enable you to substitute a wider range of text in your programs because you can control the values of the macro variables. |
The %LET Statement
The SAS System enables you to create macro variables in several ways, but the simplest way is to use the %LET statement. The %LET statement defines one macro variable at a time and can be used to create a new macro variable or redefine the value of an existing macro variable. |
General form, %LET statement:
where:
|
Let's look at an example of a %LET statement. This statement creates
a macro variable named region that has the value
northwest.
%let region=northwest;
Notice that the macro variable value is not enclosed in
quotes. If quotes are used, they are stored as part of the value. For example,
this %LET statement creates the macro variable %let region='northwest';
Here's another example of a %LET statement. This statement creates a macro
variable named %let level=768; The value 768 is not treated as a number. All digits, characters, and symbols are processed as text strings.
This %LET statement assigns the value 700+700*.05 to the macro variable
%let rate=700+700*.05; The value 700+700*.05 is not evaluated. It is viewed strictly as a text string. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.