
Chapter 26
Finding Logic Errors in Your
Program
Finding Logic Errors in Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Using the DATA Step Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Basic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
How a Debugger Session Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Using the Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Entering Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Working with Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Assigning Commands to Function Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Using the Macro Facility with the Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Using Macros as Debugging Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Creating Customized Debugging Commands with Macros . . . . . . . . . . . . . . . . . . 418
Debugging a DATA Step Generated by a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Example 1: Debugging a Simple DATA Step When Output Is Missing . . . . . . . . 419
Example 2: Working with Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Example 3: Debugging DO Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Example 4: Examining Formatted Values of Variables . . . . . . . . . . . . . . . . . . . . . 430
Finding Logic Errors in Your Program
Purpose
The DATA step debugger, which consists of windows and a group of commands, helps
you to interactively identify logic errors, and sometimes data errors, in your SAS
programs. Unlike syntax errors, logic errors do not stop a program from running.
Instead, logic errors cause the program to produce unexpected results. For example, if
you create a DATA step that keeps track of inventory, and your program shows that you
are out of stock but your warehouse is full, you have a logic error in your program.
Prerequisites
Before continuing with this session, you should understand the concepts that are
presented in the following sections:
415