SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Debugging and Testing DATA Steps
Debugging a DATA Step


Recognizing Errors in a DATA Step Program

This section teaches you how to debug common DATA step programming errors. After completing this section, you will be able to

  • recognize and diagnose syntax errors
  • recognize and diagnose execution-time errors
  • diagnose errors in programming logic.

You know how a DATA step is compiled and executed when written correctly. You probably also know that programs are rarely written correctly the first time. Error-checking features in SAS make it easy for you to debug your program as you develop it. When you submit your program, SAS evaluates it and, if errors are detected, writes messages to the SAS log. You can browse the messages, then correct and resubmit your program.

SAS detects two types of errors:

  • Compile-time errors, including syntax errors such as missing or invalid punctuation or misspelled keywords.

     data test <-- missing semicolon
        cet finance.records; <-- misspelled word
        if code=1 then
           Type='Variable"; <-- wrong quotation mark
        else Type='Fixed';
        Interest=amount+rate;
     run;

  • Execution-time errors, such as illegal mathematical operations or processing a character variable as a numeric variable. Execution-time errors are detected after compilation, during the execution of the DATA step. In this example, Code is a character variable and so should be enclosed in quotation marks.

Description of Finance.Records

Variable Type Length
Account CHAR 8
Amount NUM 8
Rate NUM 8
Code CHAR 1

     data test;
        set finance.records;
        if code=1 then Type='Variable'; <-- quotes missing
        else Type='Fixed';
        Interest=amount+rate;
     run;
In addition, any errors in your program logic can sometimes cause a DATA step program to produce results that are different from what you expect. For example, in this program, the value of Interest should be calculated by multiplying Amount by Rate, not by adding Amount to Rate.

     data test;
        set finance.records;
        if code='1' then Type='Variable';
        else Type='Fixed';
        Interest=amount+rate; <-- '+' should be '*'

     run;

back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement