Types of Errors

There are a number of different errors you may run across when working with SAS. In some cases SAS might simply fail to start. In other cases SAS will write an ERROR message to the log file and stop processing - the details of what happens next depends on whether you are working interactively or in batch mode. In still other cases SAS will write a NOTE to the log file and produce a missing value. And in some instances SAS will write a WARNING message about a potential error. Finally, there are plenty of mistakes you can make that SAS will not detect at all.

Important

When working interactively, make a habit of checking your log before you get excited about your results. In interactive mode, SAS can continue to produce output after encountering an ERROR. Use the DMSSYNCHK system option to change this behavior.

SAS fails to start up

This is usually a configuration problem of some kind. Often a box will flash on your screen briefly, perhaps with a message about “kernel initialization” or an operating system error code.

If you have a personal sasv9.cfg file, or have created your own SAS startup icon (Windows), the problem could lie there. Review our notes on custom configurations. Otherwise, if you are an SSCC member, contact our Help desk.

SAS Errors

These are errors within your SAS code.

We can break programming errors into four types:

  • Syntax errors
  • Executable errors
  • Mathematical errors
  • Logical errors

Syntax Errors

By syntax errors we mean any error that produces code that SAS cannot interpret. These range from simple typos, to mismatched quotes, missing semi-colons, and misused SAS keywords. These are all compile-time errors.

Recognizing Compile-time versus Execution-time errors

When SAS encounters a compile-time error, the error message is generally written in the middle of the DATA/PROC step statements echoed in the log, immediately after the offending code. Execution-time errors are written after all of the statements have been echoed, after the run group.

See SAS 9.4 Language Concepts: Error Processing for more examples.

Mistyped Keywords (typos)

A common typo, particularly if you work in more than one programming language.

2          data new;
3           do i = 1 to 10;
4               x = ranuni(-1);
5               outcome; /* mistyped OUTPUT */
             _______
             180
ERROR 180-322: Statement is not valid or it is used out of proper order.

6               end;
7           run;
WARNING: The data set WORK.NEW may be incomplete.  When this step was 
         stopped there were 0 observations and 2 variables.
ERROR: Errors printed on page 1.

In some cases SAS will correctly guess the keyword you meant. You can use the NOAUTOCORRECT system option, if this annoys you.

2          prok means data=sashelp.class; /* mistyped PROC */
           ____
           14
WARNING 14-169: Assuming the symbol PROC was misspelled as prok.
3            var age;
4          run;
                            The MEANS Procedure

                         Analysis Variable : Age 
 
     N            Mean         Std Dev         Minimum         Maximum
    ------------------------------------------------------------------
    19      13.3157895       1.4926722      11.0000000      16.0000000
    ------------------------------------------------------------------

Missing Semi-colon (;)

This is arguably the most common coding error in SAS. The SAS interpreter tries to understand the next keyword as part of the previous statement. SAS generally provides a list of keywords that might have been acceptable at the end of the previous statement … but that’s not the problem!

2          data new;
3           do i = 1 to 10;
4               x = ranuni(-1)  /* missing semi-colon */
5               output;
             ______
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, 
              **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, 
              IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

6               end;
7           run;
WARNING: The data set WORK.NEW may be incomplete.  When this step was 
         stopped there were 0 observations and 3 variables.
ERROR: Errors printed on page 1.

Mismatched Quote

The error message for mismatched quotes depends on how much code is submitted after the quote.

When working interactively, SAS might appear to just hang. Mismatched quote The interpreter is waiting for you to submit more code, to finish specifying the step.

With more code, SAS might appear to be hung in the middle of a step, but also give you a NOTE.

Long string detected
Mismatched … something

When working interactively, SAS may be waiting for a quote/statement/step/comment terminator, because you forgot to type something. The “universal” fix is to submit the following code:

/* '; * "; */;
quit;
run;

In batch mode with only a little code, your error message might look like this:

2          proc means data=sashelp.class;
3           where sex =
3        ! '
           _
           22
           76
3        ! F;
ERROR 22-322: Syntax error, expecting one of the following: a name, 
              a quoted string, a numeric constant, a datetime constant, 
              a missing value, (, *, +, -, :, INPUT, NOT, PUT, ^, ~.  
ERROR 76-322: Syntax error, statement will be ignored.
4           var age;
5           run;
ERROR: Syntax error while parsing WHERE clause.
ERROR: Errors printed on page 1.

Executable Errors

An executable error occurs when your code is syntactically correct, but the resource (usually, data) that you reference is “missing” (often, misnamed or in the wrong location). This might be a file or a variable that does not exist.

Misplaced file

A really simple example is a file that does not exist.

2          data more;
3            infile "mydata.txt";
4           input x y z;
5           run;
ERROR: Physical file does not exist, 
       Z:\PUBLIC_web_source\SASnotes\home\mydata.txt.
WARNING: The data set WORK.MORE may be incomplete.  When this step was 
         stopped there were 0 observations and 3 variables.
ERROR: Errors printed on page 1.

Non-existant variable

2          proc means data=sashelp.class;
3            var mpg;
ERROR: Variable MPG not found.
4            run;
ERROR: Errors printed on page 1.

Variable not initialized

This error does not stop SAS, but it generally produces a “mising values” NOTE and a variable (or variables) that has only missing values.

2          data class;
3            set sashelp.class(obs=2);
4            barefoot_height = height - shoes;
5            run;

NOTE: Variable shoes is uninitialized.
NOTE: Missing values were generated as a result of performing an operation 
      on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      2 at 4:28   
NOTE: There were 2 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 2 observations and 7 variables.

6          
7          proc print data=class(obs=5) noobs;
8            var height shoes barefoot_height;
9            run;

NOTE: There were 2 observations read from the data set WORK.CLASS.
NOTE: The PROCEDURE PRINT printed page 1.
                                          barefoot_
                       Height    shoes      height

                        69.0       .          .    
                        56.5       .          .    

Math Errors

In particular, dividing by zero produces NOTEs.

2          data new;
3           do i = 1 to 3;
4               x = ranuni(-1);
5               y = x/0; /* math error with "NOTE" */
6               output;
7               end;
8           run;

NOTE: Division by zero detected at line 5 column 8.
NOTE: Division by zero detected at line 5 column 8.
NOTE: Division by zero detected at line 5 column 8.
i=4 x=0.6606148694 y=. _ERROR_=1 _N_=1
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).
      3 at 5:8   
NOTE: The data set WORK.NEW has 3 observations and 3 variables.

Logical Errors

It is surprisingly easy to write code that SAS has no problem interpreting, but that does not produce the result you intended. No software can guard you from these sorts of errors. This could be as simple as using the wrong variable in a model: q10 instead of q11. It could be putting calculations in a DATA step in the wrong order (anything involving conditional processing, or less commonly anything using intermediate variables).

A common example is recoding a variable without considering what to do with missing values - these may end up being lumped in one category or another. As an analyst, whenever you are creating a new variable, it should occur to you to find some way to check your result.

  • If you are rescaling a continuous variable, is the correlation between the original and the new variable one (1)?
  • If you are recategorizing a variable, does a crosstab of the original and the new variable produce a sensible table? (Did you include missing values in your crosstab?)