Table 7.7 By Function
Function Affects Groups Works At
%STR A, C* Macro compilation
%NRSTR A, B, C* Macro compilation
%BQUOTE A, C Macro execution
%NRBQUOTE A, B, C Macro execution
%SUPERQ A, B, C Macro execution (prevents
resolution)
%QUOTE A, C* Macro execution. Requires
unmatched quotation marks
and parentheses to be marked
with a percent sign (%).
%NRQUOTE A, B, C* Macro execution. Requires
unmatched quotation marks
and parentheses to be marked
with a percent sign (%).
*Unmatched quotation marks and parentheses must be marked with a percent sign (%) when
used with %STR, %NRSTR, %QUOTE, and %NRQUOTE.
Unquoting Text
Restoring the Significance of Symbols
To unquote a value means to restore the significance of symbols in an item that was
previously masked by a macro quoting function.
Usually, after an item has been masked by a macro quoting function, it retains its special
status until one of the following occurs:
You enclose the item with the %UNQUOTE function. (For more information, see
“%UNQUOTE Function” on page 292.)
The item leaves the word scanner and is passed to the DATA step compiler, SAS
procedures, SAS macro facility, or other parts of the SAS System.
The item is returned as an unquoted result by the %SCAN, %SUBSTR, or
%UPCASE function. (To retain a value's masked status during one of these
operations, use the %QSCAN, %QSUBSTR, or %QUPCASE function. For more
information, see “Other Functions That Perform Macro Quoting” on page 100.)
As a rule, you do not need to unquote an item because it is automatically unquoted when
the item is passed from the word scanner to the rest of SAS. Under two circumstances,
however, you might need to use the %UNQUOTE function to restore the original
significance to a masked item:
Unquoting Text 97
when you want to use a value with its restored meaning later in the same macro in
which its value was previously masked by a macro quoting function
when masking text with a macro quoting function changes how the word scanner
tokenizes it, producing SAS statements that look correct but that the SAS compiler
does not recognize
Example of Unquoting
The following example illustrates using a value twice: once in macro quoted form and
once in unquoted form. Suppose the macro ANALYZE is part of a system that enables
you to compare the output of two statistical models interactively. First, you enter an
operator to specify the relationship that you want to test (one result greater than another,
equal to another, and so on). The macro ANALYZE does the following:
tests the macro quoted value of the operator to verify that you have entered it
correctly
uses the unquoted value to compare the values indicated
writes a message
Match the numbers in the comments to the paragraphs below.
%macro analyze(stat);
data _null_;
set out1;
call symput('v1',&stat);
run;
data _null_;
set out2;
call symput('v2',&stat);
run;
%put Preliminary test. Enter the operator.;
%input;
%let op=%bquote(&sysbuffr);
%if &op=%str(=<) %then %let op=%str(<=);
%else %if &op=%str(=>) %then %let op=%str(>=);
%if &v1 %unquote(&op) &v2 %then
%put You might proceed with the analysis.;
%else
%do;
%put &stat from out1 is not &op &stat from out2.;
%put Please check your previous models.;
%end;
%mend analyze;
You mask the value of SYSBUFFR with the %BQUOTE function, which masks
resolved items including unmatched, unmarked quotation marks and parentheses (but
excluding the ampersand and percent sign).
The %IF condition compares the value of the macro variable OP to a string to see
whether the value of OP contains the correct symbols for the operator. If the value
contains symbols in the wrong order, the %THEN statement corrects the symbols.
Because a value masked by a macro quoting function remains masked, you do not need
to mask the reference &OP in the left side of the %IF condition.
98 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