Chapter Contents

Previous

Next
%BQUOTE and %NRBQUOTE

%BQUOTE and %NRBQUOTE



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

Type: Macro quoting functions
See also:
%QUOTE and %NRQUOTE
%SUPERQ


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 addition, %NRBQUOTE masks

& %

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


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 ( ' ") and parentheses ( ( )) that do not have a match do not have to be marked.

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


Comparisons


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')
Executing this program writes to the log:
FILE "myfile"
FILE 'myfile'


Chapter Contents

Previous

Next

Top of Page

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