Chapter Contents

Previous

Next

Types of Errors


Syntax Errors

Syntax errors occur when program statements do not conform to the rules of the SAS language. Examples of syntax errors include

When SAS encounters a syntax error, it first attempts to correct the error by attempting to interpret what you meant, then continues processing your program based on its assumptions. If SAS cannot correct the error, it prints an error message to the log.

In the following example, the DATA statement is misspelled, and SAS prints a warning message to the log. Because SAS could interpret the misspelled word, the program runs and produces output.

date temp;
   x=1;
run;

proc print data=temp;
run;

SAS Log: Syntax Error (misspelled key word)
1    date temp;
     ----
     14
WARNING 14-169: Assuming the symbol DATA was misspelled as date.

2       x=1;
3    run;

NOTE: The data set WORK.TEMP has 1 observations and 1 variables.
NOTE: DATA statement used:
      real time           0.17 seconds
      cpu time            0.04 seconds


4
5    proc print data=temp;
6    run;

NOTE: PROCEDURE PRINT used:
      real time           0.14 seconds
      cpu time            0.03 seconds

Some errors are explained fully by the message that SAS prints in the log; other error messages are not as easy to interpret because SAS is not always able to detect exactly where the error occurred. For example, when you fail to end a SAS statement with a semicolon, SAS does not always detect the error at the point where it occurs because SAS statements are free-format (they can begin and end anywhere). In the following example, the semicolon at the end of the DATA statement is missing. SAS prints the word ERROR in the log, identifies the possible location of the error, prints an explanation of the error, and stops processing the DATA step.

data temp
   x=1;
run;

proc print data=temp;
run;

SAS Log: Syntax Error (missing semicolon)
1    data temp
2       x=1;
         -
         76
ERROR 76-322: Syntax error, statement will be ignored.

3    run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used:
      real time           0.11 seconds
      cpu time            0.02 seconds


4
5    proc print data=temp;
ERROR: File WORK.TEMP.DATA does not exist.
6    run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used:
      real time           0.06 seconds
      cpu time            0.01 seconds

Whether subsequent steps are executed depends on which method of running SAS you use, as well as on your operating environment.

Operating Environment Information:   For more information, see the SAS documentation for your operating environment.   [cautionend]


Semantic Errors

Semantic errors occur when the form of the elements in a SAS statement is correct, but the elements are not valid for that usage. Semantic errors are detected at compile time and can cause SAS to enter syntax check mode. (For a description of syntax check mode, see Syntax Check Mode.)

Examples of semantic errors include

In the following example, SAS detects an illegal reference to the array ALL.

data _null_;    
   array all{*} x1-x5;    
   all=3;
   datalines; 
1 1.5 
. 3
2 4.5
3 2 7
3 . .
;   

run;

SAS Log: First Example of a Semantic Error
      cpu time            0.02 seconds
      
1    data _null_;
2       array all{*} x1-x5;
ERROR: Illegal reference to the array all.
3       all=3;
4       datalines;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used:
      real time           2.28 seconds
      cpu time            0.06 seconds
      
10   ;
11   

The following is another example of a semantic error. In this DATA step, the libref SOMELIB has not been previously assigned in a LIBNAME statement.

data test;
   set somelib.old;
run;

SAS Log:Second Example of a Semantic Error
      cpu time            0.00 seconds
      
1   data test;
ERROR: Libname SOMELIB is not assigned.
2      set somelib.old;
3   run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST may be incomplete.  When this step was stopped 
         there were 0 observations and 0 variables.
NOTE: DATA statement used:
      real time           0.17 seconds


Execution-Time Errors

Definition

Execution-time errors occur when SAS executes a program that contains data values. Most execution-time errors produce warning messages or notes in the SAS log but allow the program to continue executing. (footnote 1)The location of an execution-time error is usually given as line and column numbers in a note or error message.

Common execution-time errors include the following:


Out-of-Resources Condition

An execution-time error can also occur when you encounter an out-of-resources condition, such as a full disk, or insufficient memory for a SAS procedure to complete. When these conditions occur, SAS attempts to find resources for current use. For example, SAS may ask the user for permission to delete temporary data sets that might no longer be needed, or to free the memory in which macro variables are stored.

When an out-of-resources condition occurs in a windowing environment, you can use the SAS CLEANUP system option to display a requestor panel that enables you to choose how to resolve the error. When you run SAS in batch, noninteractive, or interactive line mode, the operation of CLEANUP depends on your operating environment. For more information about this system option, see CLEANUP in the "SAS System Options" chapter in SAS Language Reference: Dictionary, and in the SAS documentation for your operating environment.

Examples

In the following example, an execution-time error occurs when SAS uses data values from the second observation to perform the division operation in the assignment statement. Division by 0 is an illegal mathematical operation and causes an execution-time error.

options linesize=64 nodate pageno=1 pagesize=25;

data inventory;
   input Item $ 1-14 TotalCost 15-20 
         UnitsOnHand 21-23;
   UnitCost=TotalCost/UnitsOnHand;
   datalines;
Hammers       440   55
Nylon cord    35    0
Ceiling fans  1155  30
;

proc print data=inventory;
   format TotalCost dollar8.2 UnitCost dollar8.2;
run;

SAS Log: Execution-Time Error
      cpu time            0.02 seconds
      
1    
2    options linesize=64 nodate pageno=1 pagesize=25;
3    
4    data inventory;
5      input Item $ 1-14 TotalCost 15-20
6            UnitsOnHand 21-23;
7      UnitCost=TotalCost/UnitsOnHand;
8      datalines;
NOTE: Division by zero detected at line 12 column 22.
RULE:----+----1----+----2----+----3----+----4----+----5----+----
10   Nylon cord    35    0
Item=Nylon cord TotalCost=35 UnitsOnHand=0 UnitCost=. _ERROR_=1
_N_=2
NOTE: Mathematical operations could not be performed at the 
      following places. The results of the operations have been 
      set to missing values.
      Each place is given by: 
      (Number of times) at (Line):(Column).
      1 at 12:22   
NOTE: The data set WORK.INVENTORY has 3 observations and 4 
      variables.
NOTE: DATA statement used:
      real time           2.78 seconds
      cpu time            0.08 seconds
      
12   ;
13   
14   proc print data=inventory;
15      format TotalCost dollar8.2 UnitCost dollar8.2;
16   run;
NOTE: There were 3 observations read from the dataset 
      WORK.INVENTORY.
NOTE: PROCEDURE PRINT used:
      real time           2.62 seconds

SAS Output: Execution-Time Error
                         The SAS System                        1

                               Total     Units
     Obs    Item                Cost     OnHand    UnitCost

      1     Hammers          $440.00       55         $8.00
      2     Nylon cord        $35.00        0           .  
      3     Ceiling fans    $1155.00       30        $38.50

SAS executes the entire step, assigns a missing value for the variable UnitCost in the output, and writes the following to the SAS log:

Note that the values listed in the program data vector include the _N_ and _ERROR_ automatic variables. These automatic variables are assigned temporarily to each observation and are not stored with the data set.

In the following example of an execution-time error, the program processes an array and SAS encounters a value of the array's subscript that is out of range. SAS prints an error message to the log and stops processing.

options linesize=64 nodate pageno=1 pagesize=25;

data test;
   array all{*} x1-x3;
   input I measure;
   if measure > 0 then
      all{I} = measure;
   datalines;
1 1.5
. 3
2 4.5
;

proc print data=test;
run;

      cpu time            0.02 seconds
      
1    options linesize=64 nodate pageno=1 pagesize=25;
2    
3    data test;
4       array all{*} x1-x3;
5      input I measure;
6      if measure > 0 then
7         all{I} = measure;
8      datalines;
ERROR: Array subscript out of range at line 12 column 7.
RULE:----+----1----+----2----+----3----+----4----+----5----+----
10   . 3
x1=. x2=. x3=. I=. measure=3 _ERROR_=1 _N_=2
NOTE: The SAS System stopped processing this step because of 
      errors.
WARNING: The data set WORK.TEST may be incomplete.  When this 
         step was stopped there were 1 observations and 5 
         variables.
NOTE: DATA statement used:
      real time           0.90 seconds
      cpu time            0.09 seconds
      
12   ;
13   
14   proc print data=test;
15   run;
NOTE: There were 1 observations read from the dataset WORK.TEST.
NOTE: PROCEDURE PRINT used:
      real time           0.81 seconds


Data Errors

Data errors occur when some data values are not appropriate for the SAS statements that you have specified in the program. For example, if you define a variable as numeric, but the data value is actually character, SAS generates a data error. SAS detects data errors during program execution and continues to execute the program, and does the following:

In this example, a character value in the Number variable results in a data error during program execution:

options linesize=64 nodate pageno=1 pagesize=25;

data age;
   input Name $ Number;
   datalines;
Sue 35
Joe xx
Steve 22
;

proc print data=age;
run;

The SAS log shows that there is an error in line 61, position 5-6 of the program.

SAS Log: Data Error
      cpu time            0.01 seconds
      
1   
2   options linesize=64 nodate pageno=1 pagesize=25;
3   
4   data age;
5      input Name $ Number;
6      datalines;
NOTE: Invalid data for Number in line 61 5-6.
RULE:----+----1----+----2----+----3----+----4----+----5----+----
8   Joe xx
Name=Joe Number=. _ERROR_=1 _N_=2
NOTE: The data set WORK.AGE has 3 observations and 2 variables.
NOTE: DATA statement used:
      real time           0.06 seconds
      cpu time            0.02 seconds
      
10   ;
11   
12   proc print data=age;
13   run;
NOTE: There were 3 observations read from the dataset WORK.AGE.
NOTE: PROCEDURE PRINT used:
      real time           0.01 seconds

SAS Output: Data Error
                         The SAS System                        1

                     Obs    Name     Number

                      1     Sue        35  
                      2     Joe         .  
                      3     Steve      22  

You can also use the INVALIDDATA= system option to assign a value to a variable when your program encounters invalid data. For more information, see the INVALIDDATA= system option in SAS Language Reference: Dictionary.

Format Modifiers for Error Reporting

The INPUT statement uses the ? and the ?? format modifiers for error reporting. The format modifiers control the amount of information that is written to the SAS log. Both the ? and the ?? modifiers supress the invalid data message. However, the ?? modifier also sets the automatic variable _ERROR_ to 0. For example, these two sets of statements are equivalent:

In either case, SAS sets the invalid values of X to missing values.


Macro-related Errors

Several types of macro-related errors exist:

For more information about macros, see SAS Macro Language: Reference.


FOOTNOTE 1:  When you run SAS in noninteractive mode, more serious errors can cause SAS to enter syntax check mode and stop processing the program. [arrow]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.