options symbolgen;
/* Assign a value to EXAMPLE that contains several special */
/* characters and a mnemonic. */
%let example = %nrbquote( 1 + 1 = 3 Today's Test and More );
%put *&example*;
When this program is submitted, the following appears in the SAS log:
SYMBOLGEN: Macro variable EXAMPLE resolves to 1 + 1 = 3 Today's
Test and More
SYMBOLGEN: Some characters in the above value which were subject
to macro quoting have been unquoted for printing.
* 1 + 1 = 3 Today's Test and More *
As you can see, the leading and trailing blanks and special characters were retained in
the variable's value. When the macro processor was working with the string, the string
actually contained coded characters that were substituted for the “real” characters. The
substitute characters included coded characters to represent the start and end of the
string. The leading and trailing blanks were preserved. Characters were also substituted
for the special characters +, =, and ', and the mnemonic AND. When the macro finished
processing and the characters were passed to the rest of SAS, the coding was removed
and the real characters were replaced.
“Unquoting Text” on page 97 provides more information about what happens when a
masked string is unquoted. For more information, see “SYMBOLGEN System Option”
on page 385.
Other Functions That Perform Macro Quoting
Functions That Start with the Letter Q
Some macro functions are available in pairs, where one function starts with the letter Q:
• %SCAN and %QSCAN
• %SUBSTR and %QSUBSTR
• %UPCASE and %QUPCASE
• %SYSFUNC and %QSYSFUNC
The Qxxx functions are necessary because by default, macro functions return an
unquoted result, even if the argument was masked by a macro quoting function. The
%QSCAN, %QSUBSTR, %QUPCASE, and %QSYSFUNC functions mask the returned
value at execution time. The items masked are the same as the items masked by the
%NRBQUOTE function.
Example Using the %QSCAN Function
The following macro uses the %QSCAN function to assign items in the value of
SYSBUFFR (described in “Automatic Macro Variables” on page 198) as the values of
separate macro variables. The numbers in the comments correspond to the explanations
in the list that follows the macro code.
100 Chapter 7 • Macro Quoting