%let dsname=Newdata;
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.
&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;
A character string.
The following statements show several ways that the value
maple can be assigned to macro variable STREET. In each
case, the macro processor stores the five-character value maple as the value of STREET. The leading and trailing
blanks are not stored. %let street=maple; %let street= maple; %let street=maple ;Note: Quotation marks are not required. If quotation marks are used, they become part of the value. |
|
The %EVAL function,
for example,
%let num=%eval(100+200); / * produces 300 * /use the %SYSEVALF function, for example, %let num=%sysevalf(100+1.597); / * produces 101.597 * /For more information, see Macro Evaluation Functions. |
|
A macro variable reference, ¯o-variable. For example,
%let street=Maple; %let num=123; %let address=&num &street Avenue;This example shows multiple macro references that are part of a text expression. The macro processor attempts to resolve text expressions before it makes the assignment. Thus, the macro processor stores the value of macro variable ADDRESS as 123 Maple Avenue .
You can treat ampersands
and percent signs as literals by using the %NRSTR function to mask
the character so that the macro processor treats it as text instead
of trying to interpret it as a macro call. See Macro Language Elements and Macro Quoting for information.
|
|
Macro quoting function
%STR or %NRSTR around the value. This action masks the blanks or special
characters so that the macro processor interprets them as text. See Macro Quoting Functions. For example,
%let state=%str( North Carolina); %let town=%str(Taylor%'s Pond); %let store=%nrstr(Smith&Jones); %let plotit=%str( proc plot; plot income*age; run;);The definition of macro variable TOWN demonstrates using %STR to mask a value containing an unmatched quotation mark. Macro Quoting Functions discuss macro quoting functions that require unmatched quotation marks and other symbols to be marked. The definition of macro
variable PLOTIT demonstrates using %STR to mask blanks and special
characters (semicolons) in macro variable values. When a macro
variable contains complete SAS statements, the statements are easier
to read if you enter them on separate lines with indentions for
statements within a DATA or PROC step. Using a macro quoting function
retains the significant blanks in the macro variable value.
|
|
The SYMPUT routine.
This example puts the number of observations in a data set into
a FOOTNOTE statement where AGE is greater than 20:
data _null_; set in.permdata end=final; if age>20 then n+1; if final then call symput('number',trim(left(n))); run; footnote "&number Observations have AGE>20";During the last iteration of the DATA step, the SYMPUT routine creates a macro variable named NUMBER whose value is the value of N. (SAS also issues a numeric-to-character conversion message.) The TRIM and the LEFT functions remove the extra space characters from the DATA step variable N before its value is assigned to the macro variable NUMBER. For a discussion of
SYMPUT, including information about preventing the numeric-character
message, see CALL SYMPUT Routine.
|