Typically SAS issues warning and error messages to provide diagnostics to aid you in correcting problems in coding an SAS program. Most of these messages are self-explanatory; however, some require some experience before you will be able to interpret them correctly and on rare occassions, a SAS program will terminate without generating an error. One way to learn how to interpret error messages is to deliberately include errors into a functioning program and note the error messages which are generated.
Enter the following code in the program editor window:
OPTIONS LINESIZE=72; TITLE 'Product Survey';
* The following data are from a survey of the quality ratings of three products. The variable INC is the person's annual income expressed in thousands of dollars. ;
DATA survey; INPUT id 1-3 sex $ 6 age 9-10 inc 12-13 r1 16 r2 17 r3 18; CARDS; 1 F 35 17 722 17 M 50 14 553 PROC PRINT; RUN;
You may use mixed, lower, or upper case in your SAS statements. SAS statements may begin in any column and may be broken across lines; however, each SAS statement must end with a semicolon. The most common source of errors made by beginning SAS programmers is the omission of one of these required semicolons.
Execute the above program. The program will execute and if there are no errors, the program output will be displayed in the Output Window. After examining the output, enter the command LOG on the Command line of the Output window to restore the Log window. The program plus diagnostic messages are displayed in the Log Window. Scroll or page up in this window and observe:
If there are any errors, SAS will underscore the first error it encounters and print an error code below it. The associated error codes are defined in the SASLOG.
Note: The underscored text may not be the cause of the error.
On the Command line of the Log window, enter PROG to restore the Program Editor window. To become familiar with SAS error diagnostic messages, use the recall command to bring the above program back into the program editor. Delete the semicolon following the comment, e.g., delete the semicolon following the word "dollars." in the above example. Submit the program for execution and observe the error messages as they are written to the LOG window. You may see messages similar to the following listed after the CARDS statement:
0ERROR 180: STATEMENT IS NOT VALID OR IT IS USED OUT OF PROPER ORDER. +ERROR 180: STATEMENT IS NOT VALID OR IT IS USED OUT OF PROPER ORDER. +ERROR 180: STATEMENT IS NOT VALID OR IT IS USED OUT OF PROPER ORDER. 0ERROR 184: CARDS OR PARMCARDS STATEMENT NOT ALLOWED HERE. +ERROR 184: CARDS OR PARMCARDS STATEMENT NOT ALLOWED HERE. +ERROR 184: CARDS OR PARMCARDS STATEMENT NOT ALLOWED HERE. ERROR: DATA SET WORK._NULL_ NOT FOUND. +ERROR: DATA SET WORK._NULL_ NOT FOUND. +ERROR: DATA SET WORK._NULL_ NOT FOUND.
In this example, one missing semicolon generated several error messages. In more complex programs, a missing semicolon may generate even more errors. If you have an error in a SAS program, the first thing to do is to check backwards from the first error message to be sure that all required semicolons have been included.
Note: The error messages appear in the LOG Window. You must make the changes in your SAS program. Otherwise you will receive the same error message as it had not been corrected in your original program.
The following sections are provided to help you with a guide to some of the most commonly encountered errors.
The most common error is to forget a semicolon at the end of a SAS statement. Such an error can result in the generation of error messages in lines of code which are perfectly valid. If you have an error, locate the first error message within the SAS program and check for a missing semicolon.
Documenting programs is recommended so that you remember what the program is supposed to do; however, remember that the last comment line must be terminated by a semicolon.
Note: If a semicolon is included within a multi-line comment, the semicolon indicates the end of the comment and SAS will try to execute whatever statement follows the semicolon, unless it, too, is preceded by an asterisk or the word COMMENT.
If no data set is explicitly defined, SAS uses the last data set defined. If you have defined a data set with a DATA statement and then follow this by a PROC statement which includes an OUTPUT statement, SAS will use this output data set from the PROC as the input to any subsequent procedures that do not specify a data set to operate on, or until another data step is executed. Thus, although it is not required, it is good practice to include a DATA= statement with each PROC statement.
Check your data to be sure that it does not contain blank lines or semicolons. Either of these conditions may result in very cryptic error messages which are difficult to trace.
If you are working in a windowing environment and have several open applications, recall and save (use the FILE command) your SAS code. Then quit from SAS and close down all open applications. Then restart SAS and rerun your code. If this fails, consider modifications to your code so that less memory would be required to execute or consider executing the program on one of the central UNIX compute servers.
If you run out of disk space while executing an SAS program, delete unnecessary files from your disk and try to execute the program again. If this is not sufficient, consider purchase of additional disk space.
In some environments, SAS will stop processing data when a divide by zero condition is encountered; a warning message is issued in later versions of the SAS System. Consider the following program:
DATA one ;
INPUT a b c d ;
z = ( (a+b) / (a+b+c) ) * 100 ;
CARDS ;
0 0 0 0
-2 1 1 1
0 0 0 1
1 1 1 1
1 2 3 4
5 6 7 0
7 8 9 10
PROC PRINT;
Note: Here the value of the divisor (a+b+c) used to create the variable z is zero for the first observation. When this problem occurs, the SAS log will include error diagnostics similar to the following:
NOTE: The data step has been abnormally terminated. NOTE: 1 record was read from the infile IN1. NOTE: The data set WORK.filename has 0 observations and 5 variables.
The error diagnostics indicate an abnormal program termination, but without an explanation as to the cause. To correct this problem, create a new variable corresponding to the divisor and evaluate the value of this variable prior to attempting the division, e.g.:
x = a + b ; y = x + c ; IF y > 0 THEN z = 100 * x/y ; ELSE z = 0 ;
Bad code that SAS cannot resolve can sometimes cause a mainframe program to terminate with minimal or no error diagnostics. Consider the following code which was designed to process some data originally saved from a Quattro Spreadsheet which used "*" as a missing value indicator:
DATA one ;
INPUT a b c d ;
IF b = * THEN DELETE ;
IF b = . THEN DELETE ;
CARDS ;
1 2 3 4
5 . 7 0
7 * 9 10
PROC PRINT;
The missing statement can be used in SAS to associate alphabetic
characters or the underscore (_) character with missing values,
but not the asterisk (*).
User Services
Virginia Tech Computing Center