Chapter Contents


SAS Macro Language: Reference

General Debugging Information

Because the macro facility is such a powerful tool, it is also complex, and debugging large macro applications can be extremely time-consuming and frustrating. Therefore, it makes sense to develop your macro application in a way that minimizes the errors and that makes the errors that do occur as easy as possible to find and fix. The first step is to understand what kind of errors can occur and when they manifest themselves. Then, develop your macros using a modular, layered approach. Finally, use some built-in tools such as system options, automatic macro variables, and the %PUT statement to diagnose errors.

Note:   To receive certain important warning messages about unresolved macro names and macro variables, be sure the system options SERROR and MERROR are in effect. See Chapter 13, "Macro Language Dictionary," for more information on these system options.  [cautionend]

Understanding What Kind of Errors You Can Encounter

When the word scanner processes a program and finds a token in the form of & or %, it triggers the macro processor to examine the name token that follows the & or %. Depending on the token, the macro processor initiates one of the following activities:

An error can occur during any one of these stages. For example, if you misspell a macro function name or omit a necessary semicolon, that is a syntax error during compilation. Syntax errors occur when program statements do not conform to the rules of the macro language. Or, you may refer to a variable out of scope, causing a macro variable resolution error. Execution errors (also called semantic errors) are usually errors in program logic. They can occur, for example, when the text generated by the macro has faulty logic (statements not executed in the right order or in the way you expect).

Of course, your macro code can be perfect--that does not guarantee that you will not encounter errors caused by plain SAS code, such as a libref not defined, or a syntax error in open code (that is, outside of a macro definition), or a typo in the code your macro generates. Typically, error messages with numbers are plain SAS code error messages; error messages generated by the macro processor do not have numbers.

Developing Bug-free Macros

When programming in any language, it is good technique to develop your code in modules. That is, instead of writing one massive program, develop it piece by piece, test each piece separately, then put the pieces together. This technique is especially useful when developing macro applications because of the two-part nature of SAS macros: macro code and the SAS code generated by the macro code.

Another good idea is to proofread your macro code for common mistakes before you submit it.

The following list gives some simple things whose omission can cause errors--by proofreading your code, you can catch these problems before compiling your code:

Chapter Contents



Top of Page

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