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
%macro splitit;
%put What character separates the values?; 1
%input;
%let s=%bquote(&sysbuffr); 2
%put Enter three values.;
%input;
%local i;
%do i=1 %to 3; 3
%global x&i;
%let x&i=%qscan(%superq(sysbuffr),&i,&s);
4
%end;
%mend splitit;
%splitit
What character separates the values?
#
Enter three values.
Fischer Books#Smith&Sons#Sarah's Sweet Shoppe
5
1. This question asks you to input a delimiter for the %QSCAN function that does not
appear in the values that you enter.
2. Masking the value of SYSBUFFR with the %BQUOTE function enables you to
choose a quotation mark or parenthesis as a delimiter if necessary.
3. The iterative %DO loop creates a global macro variable for each segment of
SYSBUFFR and assigns it the value of that segment.
4. The %SUPERQ function masks the value of SYSBUFFR in the first argument of the
%QSCAN function. It prevents any resolution of the value of SYSBUFFR.
5. The %QSCAN function returns macro quoted segments of the value of SYSBUFFR.
Thus, the unmatched quotation mark in Sarah's Sweet Shoppe and the &name
pattern in Smith&Sons do not cause problems.
Other Functions That Perform Macro Quoting 101
102 Chapter 7 Macro Quoting
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset