Macro Facility,” on page 391. If you assign a macro variable name that is not valid, an
error message is printed in the SAS log.
You can use %PUT _ALL_ to view all user-created macro variables.
Creating User-Defined Macro Variable Names
The simplest way to create a user-defined macro variable is to use the macro program
statement %LET:
%let dsname=Newdata;
DSNAME is the name of the macro variable. Newdata is the value of the macro
variable DSNAME. The following are the rules for creating a macro variable:
1. SAS macro variable names can be up to 32 characters in length.
2. The first character must begin with a letter or an underscore. Subsequent characters
can be letters, numeric digits, or underscores.
3. A macro variable name cannot contain blanks.
4. A macro variable name cannot contain double-byte character set (DBCS) characters.
5. A macro variable name cannot contain any special characters other than the
underscore.
6. Macro variable names are case insensitive. For example, cat, Cat, and CAT all
represent the same variable.
7. You can assign any name to a macro variable as long as the name is not a reserved
word. The prefixes AF, DMS, SQL, and SYS are not recommended because they are
frequently used in SAS software for automatic macro variables. Thus, using one of
these prefixes can cause a name conflict with an automatic macro variable. For a
complete list of reserved words in the macro language, see Appendix 1, “ Reserved
Words in the Macro Facility,” on page 391. If you assign a macro variable name that
is not valid, an error message is printed in the SAS log.
Assigning Values to Macro Variables
The simplest way to assign a value to a macro variable is to use the macro program
statement %LET:
%let dsname=Newdata;
DSNAME is the name of the macro variable. Newdata is the value of the macro
variable DSNAME. The value of a macro variable is simply a string of characters. The
characters can include any letters, numbers, or printable symbols found on your
keyboard, and blanks between characters. The case of letters is preserved in a macro
variable value. Some characters, such as unmatched quotation marks, require special
treatment, which is described later.
If a macro variable already exists, a value assigned to it replaces its current value. If a
macro variable or its value contains macro triggers (% or &), the trigger is evaluated
before the value is assigned. In the following example, &name is resolved to Cary and
then it is assigned as the value of
city in the following statements:
%let name=Cary;
%let city=&name;
Generally, the macro processor treats alphabetic characters, digits, and symbols (except
& and %) as characters. It can also treat & and % as characters using a special treatment,
Macro Variables Defined by Users 29