Chapter Contents

Previous

Next
SAS Macro Language: Reference

Other Functions That Perform Macro Quoting

Some macro functions are available in pairs, where one function starts with the letter Q:

The Qxxx functions are necessary because by default, macro functions return an unquoted result, even if the argument was masked by a macro quoting function. The %QSCAN, %QSUBSTR, %QUPCASE, and %QSYSFUNC functions mask the returned value. The items masked are the same as those masked by the %NRBQUOTE function.


Example Using the %QSCAN Function

The following macro uses the %QSCAN function to assign items in the value of SYSBUFFR (described in Chapter 13) as the values of separate macro variables. The numbers in the comments correspond to the explanations in the list that follows the macro code.

%macro splitit;
   %put What character separates the values?;  [1]
   %input;
   %let s=%bquote(&sysbuffr);   [2]
   %put Enter three values.;
   %input;
   %local i;
   %do i=1 %to 3;  [3]
      %global x&i;
      %let x&i=%qscan(%superq(sysbuffr),&i,&s);  [4]
   %end;
%mend splitit;

%splitit
What character separates the values?
#
Enter three values.
Fischer Books#Smith&Sons#Sarah's Sweet Shoppe  [5]
  1. This question asks you to input a delimiter for the %QSCAN function that will not appear in the values you are going to enter.

  2. Masking the value of SYSBUFFR with the %BQUOTE function allows you to choose a quotation mark or parenthesis as a delimiter if necessary.

  3. The iterative %DO loop creates a global macro variable for each segment of SYSBUFFR and assigns it the value of that segment.

  4. The %SUPERQ function masks the value of SYSBUFFR in the first argument of the %QSCAN function. It prevents any resolution of the value of SYSBUFFR.

  5. The %QSCAN function returns macro quoted segments of the value of SYSBUFFR; thus, the unmatched quotation mark in Sarah's Sweet Shoppe and the &name pattern in Smith&Sons do not cause problems.


Chapter Contents

Previous

Next

Top of Page

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