Macro quoting functions tell
the macro processor to interpret special characters and mnemonics
as text rather than as part of the macro language. If you did not
use a macro quoting function to mask the special characters, the macro
processor or the rest of SAS might give the character a meaning that
you did not intend. Here are some examples of the types of ambiguities
that can arise when text strings contain special characters and mnemonics:
-
Is
%sign
a call to the macro SIGN or a phrase “percent sign”?
-
Is OR the mnemonic Boolean operator
or the abbreviation for Oregon?
-
Is the quotation mark in O'Malley
an unbalanced single quotation mark or just part of the name?
-
Is Boys&Girls a reference to
the macro variable &GIRLS or a group of children?
-
Is GE the mnemonic for “greater
than or equal” or is it short for General Electric?
-
Which statement does a semicolon
end?
-
Does a comma separate parameters,
or is it part of the value of one of the parameters?
Macro quoting functions
enable you to clearly indicate to the macro processor how it is to
interpret special characters and mnemonics.
Here is an example,
using the simplest macro quoting function, %STR. Suppose you want
to assign a PROC PRINT statement and a RUN statement to the macro
variable PRINT. Here is the erroneous statement:
%let print=proc print; run;; /* undesirable results */
This code is ambiguous.
Are the semicolons that follow PRINT and RUN part of the value of
the macro variable PRINT, or does one of them end the %LET statement?
If you do not tell the macro processor what to do, it interprets the
semicolon after PRINT as the end of the %LET statement. So the value
of the PRINT macro variable would be the following:
The rest of the characters
(RUN;;) would be simply the next part of the program.
To avoid the ambiguity
and correctly assign the value of PRINT, you must mask the semicolons
with the macro quoting function %STR, as follows:
%let print=%str(proc print; run;);