Chapter Contents


SAS Macro Language: Reference


The %SUPERQ function locates the macro variable named in its argument and quotes the value of that macro variable without permitting any resolution to occur. It masks all items that may require macro quoting at macro execution. Because %SUPERQ does not attempt any resolution of its argument, the macro processor does not issue any warning messages that a macro variable reference or a macro invocation has not been resolved. Therefore, even when the %NRBQUOTE function allows the program to work correctly, you can use the %SUPERQ function to eliminate unwanted warning messages from the SAS log. %SUPERQ takes as its argument a macro variable name without an ampersand or a text expression that yields a macro variable name.

%SUPERQ retrieves the value of a macro variable from the macro symbol table and quotes it immediately, preventing the macro processor from making any attempt to resolve anything that may occur in the resolved value. For example, if the macro variable CORPNAME resolves to Smith&Jones, using %SUPERQ prevents the macro processor from attempting to further resolve &Jones. This %LET statement successfully assigns the value Smith&Jones to TESTVAR:

%let testvar=%superq(corpname);

Examples Using %SUPERQ

This example shows how the %SUPERQ function affects two macro invocations, one for a macro that has been defined and one for an undefined macro:

%macro a;
   %put *** This is a. ***;
%mend a;

%macro test;
   %put *** Enter two values: ***;
   %put *** %superq(sysbuffr) ***;    /* Note absence of ampersand */
%mend test;

Suppose you invoke the macro TEST and respond to the prompt as shown:

*** Enter two values: ***
%a %x

The second %PUT statement simply writes the following line:

*** %a %x ***

It does not invoke the macro A, and it does not issue a warning message that %X was not resolved. See Chapter 13 for a description of SYSBUFFR.

The following two examples compare the %SUPERQ function with other macro quoting functions.

Using the %SUPERQ Function to Prevent Warning Messages

The discussions of the %NRBQUOTE function showed that this function causes the macro processor to attempt to resolve the patterns &name and %name the first time it encounters them; if the macro processor cannot resolve them, it quotes the ampersand or percent sign so that later uses of the value do not cause the macro processor to recognize them. However, if the MERROR or SERROR option is in effect, the macro processor issues a warning message that the reference or invocation was not resolved.

The macro FIRMS3, shown here, shows how the %SUPERQ function can prevent unwanted warning messages:

%macro firms3;
   %global code;
   %put Enter the name of the company;
   %let name=%superq(sysbuffr);
   %if &name ne %then %let code=valid;
   %else %let code=invalid;
   %put *** &name is &code ***;
%mend firms3;

Suppose you invoke the macro FIRMS3 twice and respond with the companies shown here:

A&A Autos

After the macro executes, the following is written to the SAS log:

*** A&A Autos is valid ***
*** Santos&D'Amato is valid ***

Using the %SUPERQ Function to Enter Macro Keywords

Suppose you create an online training system in which users can enter problems and questions that another macro prints for you later. The user's response to a %INPUT statement is assigned to a local macro variable and then to a global macro variable. Because the user is asking questions about macros, he or she may enter all sorts of macro variable references and macro calls as examples of problems, as well as unmatched, unmarked quotation marks and parentheses. If you mask the response with %BQUOTE, you have to use a few %PUT statements to warn the user about responses that cause problems. If you use the %SUPERQ function, you need fewer instructions. The macros ASK1 and ASK2 show how the macro code becomes simpler as you change macro quoting functions.

The macro ASK1, below, shows how the macro looks when you use the %BQUOTE function:

%macro ask1;
   %global myprob;
   %local temp;
   %put Describe the problem.;
   %put Do not use macro language keywords, macro calls,;
   %put or macro variable references.;
   %put Enter /// when you are finished.;
   %do %until(%bquote(&sysbuffr) eq %str(///));
      %let temp=&temp %bquote(&sysbuffr);
   %let myprob=&temp;
%mend ask1;
The macro ASK1 does not include a warning about unmatched quotation marks and parentheses. You can invoke the macro ASK1 and enter a problem as shown:
Describe the problem.
Do not use macro language keywords, macro calls,
or macro variable references.
Enter /// when you are finished.
Why didn't my macro run when I called it? (It had three
parameters, but I wasn't using any of them.) It ran
after I submitted the next statement.

Notice that both the first and second lines of the response contain an unmatched, unmarked quotation mark and parenthesis. %BQUOTE can handle these characters.

The macro ASK2, shown here, modifies the macro ASK1 by using the %SUPERQ function. Now the %INPUT statement accepts macro language keywords and does not attempt to resolve macro calls and macro variable references:

%macro ask2;
   %global myprob;
   %local temp;
   %put Describe the problem.;
   %put Enter /// when you are finished.;
   %do %until(%superq(sysbuffr) eq %str(///)); /* No ampersand */
      %let temp=&temp %superq(sysbuffr);   /* No ampersand */
   %let myprob=&temp;
%mend ask2;

You can invoke the macro ASK2 and enter a response as shown:

Describe the problem.
Enter /// when you are finished.
but it said I had too many parameters. What happened?

The response contains a macro language keyword, a macro invocation, and unmatched parentheses.

Chapter Contents



Top of Page

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