Previous Page | Next Page

Macro Functions

%BQUOTE and %NRBQUOTE Functions



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

%QUOTE and %NRQUOTE Functions

%SUPERQ Function


Syntax
Details
Tip
Comparisons
Example
Quoting a Variable

Syntax

%BQUOTE (character string | text expression)
%NRBQUOTE (character string | text expression)


Details

The %BQUOTE and %NRBQUOTE 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

In addition, %NRBQUOTE masks:

& %

%NRBQUOTE is most useful when the resolved value of an argument might contain

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


Tip

You can use %BQUOTE and %NRBQUOTE for all execution-time macro quoting because they mask all characters and mnemonic operators that can be interpreted as elements of macro language.

Quotation marks (' " ) do not have to be marked.

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


Comparisons

%NRBQUOTE and the %SUPERQ function mask the same items. However, %SUPERQ does not attempt to resolve a macro variable reference or a macro invocation that occurs in the value of the specified macro variable. %NRBQUOTE does attempt to resolve such references.%BQUOTE and %NRBQUOTE do not require that you mark quotation marks.


Example


Example 1: Quoting a Variable

This example tests whether a filename passed to the macro FILEIT starts with a quotation mark. Based on that evaluation, the macro creates the correct FILE command.

%macro fileit(infile);
  %if %bquote(&infile) NE %then
     %do;
         %let char1 = %bquote(%substr(&infile,1,1));
         %if %bquote(&char1) = %str(%')
             or %bquote(&char1) = %str(%")
         %then %let command=FILE &infile;
         %else %let command=FILE "&infile";
     %end;
  %put &command;
%mend fileit;

%fileit(myfile)
%fileit('myfile')

When this program executes, the following is written to the log:

FILE "myfile"
FILE 'myfile'

Previous Page | Next Page | Top of Page