Previous Page | Next Page

Macro Functions

%QUOTE and %NRQUOTE Functions



Mask special characters and mnemonic operators in a resolved value at macro execution.
Type: Macro quoting function
See also:

%BQUOTE and %NRBQUOTE Functions

%NRBQUOTE Function

%NRSTR Function

%SUPERQ Function


Syntax
Details
Comparisons
Example
Quoting a Value that Might Contain a Mnemonic Operator

Syntax

%QUOTE (character string | text expression)
%NRQUOTE (character string | text expression)


Details

The %QUOTE and %NRQUOTE functions mask a character string or resolved value of a text expression during execution of a macro or macro language statement. They mask the following special characters and mnemonic operators:

+ - * / < > = ¬ ^ ~ ; , # blank
AND OR NOT EQ NE LE LT GE GT IN

They also mask the following characters when they occur in pairs and when they are not matched and are marked by a preceding % :

' "

In addition, %NRQUOTE masks

& %

%NRQUOTE is most useful when an argument might contain a macro variable reference or macro invocation that you do not want resolved.

For a description of quoting in SAS macro language, see Macro Quoting.

Note:   The maximum level of nesting for the macro quoting functions is 10.  [cautionend]


Comparisons


Example


Example 1: Quoting a Value that Might Contain a Mnemonic Operator

The macro DEPT1 receives abbreviations for states and therefore might receive the value OR for Oregon.

%macro dept1(state);
      /* without %quote -- problems might occur */
   %if &state=nc %then
       %put North Carolina Department of Revenue;
   %else %put Department of Revenue;
%mend dept1;

%dept1(or)

When the macro DEPT1 executes, the %IF condition executes a %EVAL function, which evaluates or as a logical operator in this expression. Then the macro processor produces an error message for an invalid operand in the expression or=nc .

The macro DEPT2 uses the %QUOTE function to treat characters that result from resolving &STATE as text:

%macro dept2(state);
      /* with %quote function--problems are prevented */
   %if %quote(&state)=nc %then
       %put North Carolina Department of Revenue;
   %else %put Department of Revenue;
%mend dept2;

%dept2(or)

The %IF condition now compares the strings or and nc and writes to the SAS log:

Department of Revenue

Previous Page | Next Page | Top of Page