Log Messages: Debugging the SAS Program

Problems in programming syntax can generally be identified from the SAS log and can be corrected by recalling the program (under the run menu) into the Program Editor window to make the necessary changes. Before submitting the corrected program, it should be saved, at the same time clearing both the log and output windows.

(This section focuses only on syntax errors; however, it is also possible for SAS to calculate a new variable using syntactically correct code that results in inaccurate calculations, or in results not reflecting what the user intends. For this reason, it is always wise to check values of a new variable against values of the original variable used in the calculation (as illustrated in the section on creating new variables.)

There are 3 main types of messages that SAS will generate in the log: 1) Notes, 2) Errors, and 3) Warnings. They are highlighted here with 4 examples:

1. "NOTE"

NOTEs are always generated in the log; they provide important information about the processing of the SAS program such as:

  • number of observations and number of variables in a newly created data set.
  • length of time taken by the processing (both real and cpu time).
  • indications of certain types of programming errors.

5 NOTEs are illustrated in the above log excerpt:

  • The first NOTE indicates that numeric values have been converted to character values for the variable op01, indicating that SAS sees this variable as numeric, not character. But this variable was read in as character, suggesting another kind of problem with the variable - see the 3rd note.

  • The second NOTE indicates the converse of the first - that character values have been converted to numeric at two places in line 1210. This indicates that even though the values are specified as character (with quotes), SAS will convert them to numeric, because the variable was originally read in as numeric. The conversion can affect accuracy of results, so it is advisable to make the necessary changes. This is easily fixed, simply by taking the quotes off the values so that the statement reads readm90 = (.<daystor<=90);

  • The third NOTE indicates that SAS does not recognize the op01 variable and, in this case, precipitates the first note. The reason this variable is uninitialized is that it was spelled wrong, using opo1 (letter "o") instead of op01 (numeric "0").

  • The fourth and fifth NOTEs are always generated for DATA steps; they indicate, in this case, that the temporary SAS data set final has 5000 observations and 40 variables and that 55 seconds were needed (in real time) to process the DATA statement.

2. "ERROR"

Error messages are the most obvious clue that something is wrong with the SAS program. Unlike Notes and Warnings, the program will not complete processing until the necessary changes have been made. Because one error can result in multiple error messages, fixing the first-occurring error will frequently clear up the remaining error messages.

The above log excerpt shows a number of Error messages, all resulting from only one error. The first indication of the problem (200) denotes that the underlined symbol is not recognized. Reviewing the SAS code in the line just before **** shows that the statement set test has no semicolon. Adding  ;  at the end of the statement will resolve ALL Error messages in this program.


Warnings are frequently indications of problems in how SAS processed the program (although not always, and it should be noted that SAS may not always stop processing the program). Warnings should always be investigated.

In the above example, the WARNING indicates that SAS is expecting to find a variable called $trnadml, and an ERROR message is generated indicating that the $ symbol is not recognized. The problem, however, is that SAS does not recognize that $trnadml is a format which, because it is associated with the variable tranadm, requires a period at the end (i.e., format tranadm $trnadml. trandis $trndisl.; will resolve the problem).

A very common Warning is the one illustrated above, saying that a quoted string has become extremely long. Most frequently, the problem is a quote being inadvertently left out. In this case, adding the missing quote (i.e., '820  '<=diag02<='82099') will fix the problem and remove the Error messages showing up in the rest of the program.

This will not, however, fix an associated problem. A most important caveat when receiving this type of log message is to also check the message above the menu on the Log window. If it says, as in this example, "DATA STEP running", then steps must be taken to stop the program from running. Even though SAS will continue to process other programs, results of such programs may be inaccurate, without any indication of syntax problems showing up in the log. Several suggestions to stop the program are:

  • Submit the following line: '; run;
  • Submit the following line: *))%*'''))*/;
  • If all else fails, exit SAS entirely (making sure that the revised program has been saved) and re-start it again.

 << Previous


 Next >>