Chapter Contents

Previous

Next
SAS Macro Language: Reference

Understanding How Macro Quoting Works "Behind the Scenes"

In simple terms, when the macro processor masks a text string, it masks special characters and mnemonics within the coding scheme, and prefixes and suffixes the string with a hexadecimal character, called a delta character. The prefix character marks the beginning of the string and also indicates what type of macro quoting is to be applied to the string. The suffix character marks the end of the string. The prefix and suffix characters preserve any leading and trailing blanks contained by the string. The hexadecimal characters used to mask special characters and mnemonics and those used for the prefix and suffix characters may vary and are not portable.

There are more hexadecimal combinations possible in each byte than are needed to represent the symbols on a keyboard. Therefore, when a macro quoting function recognizes an item to be masked, the macro processor uses a previously unused hexadecimal combination for the prefix and suffix characters.

Macro functions, such as %EVAL and %SUBSTR, ignore the prefix and suffix characters. Therefore, the prefix and suffix characters do not affect comparisons.

When the macro processor is finished with a macro quoted text string, it removes the macro quoting-coded substitute characters and replaces them with the original characters. The unmasked characters are passed on to the rest of the system. Sometimes you may see a message about this unmasking, as in the following example:

/* Turn on SYMBOLGEN so you can see the messages about unquoting. */
options symbolgen;

/* Assign a value to EXAMPLE that contains several special */
/* characters and a mnemonic. */
%let example = %nrbquote( 1 + 1 = 3 Today's Test and More );

%put *&example*;

When this program is submitted, the following appears in the SAS log:

SYMBOLGEN:   Macro variable EXAMPLE resolves to  1 + 1 = 3 Today's 
             Test and More
SYMBOLGEN:   Some characters in the above value which were subject
             to macro quoting have been unquoted for printing.
* 1 + 1 = 3 Today's Test and More *

As you can see, the leading and trailing blanks and special characters were retained in the variable's value. While the macro processor was working with the string, the string actually contained coded characters that were substituted for the "real" characters. The substitute characters included coded characters to represent the start and end of the string. This preserved the leading and trailing blanks. Characters were also substituted for the special characters +, =, and ', and the mnemonic AND. When the macro finished processing and the characters were passed to the rest of the SAS System, the coding was removed and the real characters were replaced.

Unquoting Text provides more information on what happens when a masked string is unquoted. Chapter 13 describes the SYMBOLGEN system option.


Chapter Contents

Previous

Next

Top of Page

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