Debugging and Testing DATA Steps |
Lesson
Summary![]() ![]() |
This page contains |
I. Text Summary
To go to the page where a task, programming feature, or concept was presented, select a link. |
Understanding DATA Step Processing SAS processes the DATA step in two phases. During the compilation phase, each statement is scanned for syntax errors and the program data vector is created. If the DATA step compiles successfully, then the execution phase begins. Each observation in the input data set is processed, stored in the program data vector, and then written to the new data set. |
Automatic Variables The program data vector contains two automatic variables that can be used for processing. _N_ counts the number of times that
the DATA step has iterated. _ERROR_ signals the occurrence
of an error caused by the data during execution. The default value is
0, which means there is no error; when an error occurs, the value
is set to 1. |
The SAS Log A note in the SAS log displays the number of observations and variables in any new data set. |
Diagnosing Syntax Errors Missing or invalid punctuation or misspelled keywords are treated as syntax errors. These are detected during the compilation phase and underlined in the SAS log. |
Diagnosing Execution-Time Errors Illegal mathematical operations or processing character variables as numeric are considered execution-time errors. These are detected after compilation, during the execution of the DATA step. Notes in the SAS log can help you find and fix them. |
Writing a NULL Data Set You can test your DATA step program by submitting it without creating observations. Just use the keyword _NULL_ as the data set name in the DATA statement. |
Limiting Observations Another way to test a DATA step is to set the OBS= system option to 0 before processing. The OBS= option limits the number of observations read or created during execution of the DATA step. Remember to reset OBS= to MAX after you finish testing.
|
II. Syntax
To go to the page where a statement or option was presented, select a link. |
DATA _NULL_; |
OPTIONS OBS=0; |
OPTIONS OBS=MAX; |
PUT specification-1...specification-n; |
|
III. Sample Programs
data _null_; set finance.loans; Interest=amount*rate; run; options obs=0; data finance.newcalc; set finance.loans; Interest=amount*rate; run; data test; if code='1' then Type='Variable'; else if code='2' then Type='Fixed'; else put 'MY NOTE: invalid value: ' code=; run; data finance.newcalc; set finance.loans; if rate>0 then Interest=amount*(rate/12); else put 'DATA ERROR ' rate= _n_=; run;
|
IV. Points to Remember
|
![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.