Previous Page | Next Page

DATA Step Debugger

Advanced Usage: Using the Macro Facility with the Debugger

You can use the SAS macro facility with the debugger to invoke macros from the DEBUGGER LOG command line. You can also define macros and use macro program statements, such as %LET, on the debugger command line.


Using Macros as Debugging Tools

Macros are useful for storing a series of debugger commands. Executing the macro at the DEBUGGER LOG command line then generates the entire series of debugger commands. You can also use macros with parameters to build different series of debugger commands based on various conditions.


Creating Customized Debugging Commands with Macros

You can create a customized debugging command by defining a macro on the DEBUGGER LOG command line. Then invoke the macro from the command line. For example, to examine the variable COST, to execute five statements, and then to examine the variable DURATION, define the following macro (in this case the macro is called EC). Note that the example uses the alias for the EXAMINE command.

%macro ec; ex cost; step 5; ex duration; %mend ec;

To issue the commands, invoke macro EC from the DEBUGGER LOG command line:

%ec

The DEBUGGER LOG displays the value of COST, executes the next five statements, and then displays the value of DURATION.

Note:   Defining a macro on the DEBUGGER LOG command line allows you to use the macro only during the current debugging session, because the macro is not permanently stored. To create a permanently stored macro, use the Program Editor.  [cautionend]


Debugging a DATA Step Generated by a Macro

You can use a macro to generate a DATA step, but debugging a DATA step that is generated by a macro can be difficult. The SAS log displays a copy of the macro, but not the DATA step that the macro generated. If you use the DEBUG option at this point, the text that the macro generates appears as a continuous stream to the debugger. As a result, there are no line breaks where execution can pause.

To debug a DATA step that is generated by a macro, use the following steps:

  1. Use the MPRINT and MFILE system options when you execute your program.

  2. Assign the fileref MPRINT to an existing external file. MFILE routes the program output to the external file. Note that if you rerun your program, current output appends to the previous output in your file.

  3. Invoke the macro from a SAS session.

  4. In the Program Editor window, issue the INCLUDE command or use the File menu to open your external file.

  5. Add the DEBUG option to the DATA statement and begin a debugging session.

  6. When you locate the logic error, correct the portion of the macro that generated that statement or statements.

Previous Page | Next Page | Top of Page