SAS Base Programming study materials
SAS Base Programming study resources

SAS Base Programming: Error Handling

SAS Base Programming · Work through your exam, one topic at a time.

All guide sections

Error Handling

Reading the log

Distinguish compile-time from execution-time problems. Compile-time errors (unknown variable, unbalanced quotes, missing semicolon) mean the step never runs, and the message often appears far from the real cause - a missing semicolon frequently produces an error several lines later. Execution-time errors occur while observations are processed; the step runs, some records may be written, and _ERROR_ is set to 1 for the offending iteration.

Messages worth recognizing

NOTEs report conversions ("Character values have been converted to numeric"), invalid data, truncation, and uninitialized variables. A WARNING does not stop the step, but an ERROR normally does. _N_ counts iterations, not observations read. The END= option creates a temporary variable that is true on the last observation, and IN= flags which input data set contributed to the current row. OPTIONS ERRORABEND makes errors terminate a batch session instead of continuing.

Debugging tools

Use PUT or PUTLOG with _ALL_ to write the whole program data vector to the log, a trailing @ to hold the line, or a $ to print character values without padding. The LIST statement dumps the input record. DATA _NULL_ with OBS=10 lets you test logic without creating a table. Test missing values with MISSING(), NMISS(), or CMISS() rather than writing if x = . - that comparison never matches character variables and fails for special numeric missing values.

Rule of thumb

Fix the first ERROR in the log. Later errors are usually consequences of the first one.

data _null_;
  set work.orders(obs=10);
  putlog _all_;
run;