Chapter Contents

Previous

Next
%QUOTE and %NRQUOTE

%QUOTE and %NRQUOTE



Mask special characters and mnemonic operators in a resolved value at macro execution

Type: Macro quoting functions
See also:
%BQUOTE and %NRBQUOTE
%NRBQUOTE
%NRSTR
%SUPERQ


Syntax
Details
Comparisons
Example
Quoting a Value that May 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

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 may contain a macro variable reference or macro invocation that you do not want resolved.

For a description of quoting in SAS macro language, see Chapter 7 in SAS Macro Language: Reference.


Comparisons


Example

Example 1: Quoting a Value that May 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 may 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 implicitly 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


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.