Previous Page | Next Page

Macro Quoting

%SUPERQ Function


Using %SUPERQ

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 might 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 enables 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 either 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 might 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:

%window ask                                                                         
 #5 @5 'Enter two values:'                                                 
 #5 @24 val 15 attr=underline;                                       
                                                                                                        
%macro a;                                                                                
   %put *** This is a. ***;                                                   
%mend a;                                                                                   
                                                                                                         
%macro test;                                                                             
   %display ask;                                                                       
   %put *** %superq(val) ***;    /* Note absence of ampersand */     
%mend test; 

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

%test
Enter the following:  %a %x

The %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. The following two examples compare the %SUPERQ function with other macro quoting functions.


Using the %SUPERQ Function to Prevent Warning Messages

The sections about the %NRBQUOTE function show that it causes the macro processor to attempt to resolve the patterns &name and %name the first time it encounters them during macro execution. 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:

%window ask                                                                                                     
    #5 @5 'Enter the name of the company:'                                             
    #5 @37 val 50 attr=underline;                                                                
                                                                                                                               
%macro firms3;                                                                                                  
    %global code;                                                                                                
    %display ask;                                                                                                  
        %let name=%superq(val);                                                                    
           %if &name ne %then %let code=valid;                                
           %else %let code=invalid;                                                                   
           %put *** &name is &code ***;                                       
%mend firms3;                                                                                                
                                                                                                                               
%firms3   

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

A&A Autos
Santos&D'Amato

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 %WINDOW 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 might 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 used a few %PUT statements to warn the user about responses that cause problems. If you 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:

%window ask  
    #5 @5 'Describe the problem.'  
    #6 @5 'Do not use macro language keywords, macro calls,' 
    #7 @5 'or macro variable references.' 
    #9 @5 'Enter /// when you are finished.' 
   #11 @5 val 100 attr=underline;

%macro ask1;
    %global myprob; 
   %local temp;

   %do %until(%bquote(&val) eq %str(///)); 
       %display ask;   
       %let temp=&temp %bquote(&val); 
   %end; 
    %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:

%ask1

Try entering: 
Why did my macro not 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 during execution.

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

%window ask
    #5 @5 'Describe the problem.'
   #7 @5 'Enter /// when you are finished.' 
    #9 @5 val 100 attr=underline; 

%macro ask2; 
      %global myprob; 
      %local temp;

      %do %until(%superq(val) eq %str(///)); /* No ampersand */ 

          %display ask;
          %let temp=&temp %superq(val);   /* No ampersand */  
      %end; 
      %let myprob=&temp
%mend ask2;

You can invoke the macro ASK2 and enter a response:

%ask2

Try entering: 
My macro ADDRESS starts with %MACRO ADDRESS(COMPANY, 
CITY);. I called it with %ADDRESS(SMITH-JONES, INC., BOSTON),
but it said I had too many parameters. What happened?
///                                                                                                                                                                                                                                                             

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

Previous Page | Next Page | Top of Page