Sample 25283: Using the ERROR Statement to Identify a Data Error
This example shows how you can code an ERROR statement to customize error information written to the SAS log.
This DATA step computes the number of days an item has been checked out. If this number is less than zero, the ERROR statement executes. The ERROR statement writes specific text to the SAS log, sets the automatic variable _ERROR_ to 1, and lists the contents of the program data vector.
Assume that the program executes on April 13, 2001.
data usage;
-
- set corplib.circul;
-
- daysout=today()-checkout;
-
- if daysout lt 0 then do;
- error 'Days checked out less than zero: ' itemid=
- checkout= daysout=;
- end;
run;
|
The SAS log for the program follows. One error was detected where the checkout date occurred after the current date of April 13, 2001.
|
Note that SAS lists the values of the program data vector as well as the named output generated by the ERROR statement. This looks redundant. When your program can contain many errors, however, this may be important. The maximum number of times that SAS lists the program data vector in the SAS log for a DATA step is equal to the value of the ERRORS= option. Coding an ERROR statement ensures that you see all occurrences of a specific error.
|
SAS Log
12 data usage;
13 set corplib.circul;
14
15 daysout=today()-checkout;
16
17 if daysout lt 0 then do;
18 error 'Days checked out less than zero: ' itemid=
19 checkout= daysout=;
20 end;
21 run;
Days checked out less than zero: itemid=LIB0397
checkout=05/14/2001 daysout=-31
itemid=LIB0397 checkout=05/14/2001 duedate=06/14/2001
empno=001005 canrenew=Y nrenew=0
NOTE: There were 446 observations read from the dataset
CORPLIB.CIRCUL.
NOTE: The data set WORK.USAGE has 446 observations and 9
variables.
NOTE: DATA statement used:
real time 0.22 seconds
|
About the Author
Michele Burlew is a self-employed SAS programmer with more than 20 years of experience. She specializes in designing and programming a variety of SAS applications, and she has expertise in using many SAS products. Michele's extensive experience in developing programs and working with end users gives her keen insight into the needs of SAS software users.
Her books are available from the online bookstore.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This example shows how you can code an ERROR statement to customize error information written to the SAS log. This tip is from Michele Burlew.
| Type: | Sample |
| Topic: | Non SAS Authors ==> Michele Burlew Internal Administration ==> BBU
|
| Date Modified: | 2005-04-13 03:01:46 |
| Date Created: | 2005-04-11 11:13:06 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |