Previous Page | Next Page

Macro Facility Error Messages and Debugging

General Macro Debugging Information


Developing Macros in a Layered Approach

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 type 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 SERROR System Option and MERROR System Option are in effect. See System Options for Macros for more information about these system options.  [cautionend]


Encountering Errors

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 might 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, even if your macro code is perfect, that does not guarantee that you will not encounter errors caused by plain SAS code. For example, you might encounter a libref that is not defined, 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, and 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 outlines some key items to check for:

Previous Page | Next Page | Top of Page