Other Functions That Perform Macro Quoting

Functions That Start with the Letter Q

Some macro functions are available in pairs, where one function starts with the letter Q:
  • %SCAN and %QSCAN
  • %SUBSTR and %QSUBSTR
  • %UPCASE and %QUPCASE
  • %SYSFUNC and %QSYSFUNC
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 at execution time. The items masked are the same as the items 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 Automatic Macro Variables) 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 does not appear in the values that you enter.
  2. Masking the value of SYSBUFFR with the %BQUOTE function enables 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.