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 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, and 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.
Because you can see
the characters in the right side of the %IF condition and in the %LET
statement when you define the macro, you can use the %STR function
to mask them. Masking them once at compilation is more efficient than
masking them at each execution of ANALYZE.
To use the value of
the macro variable OP as the operator in the %IF condition, you must
restore the meaning of the operator with the %UNQUOTE function.