Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 37 ยท Getting Started

The SAS Log: Reading Notes, Warnings and Errors

Learn to read the SAS log like a professional: NOTE, WARNING and ERROR messages, the usual beginner mistakes, and a checklist for reviewing every run.

The log is SAS's running commentary on what it did with your program. Every beginner learns the hard way that a program can produce a plausible-looking table while the log quietly says something went wrong. Reading the log is the single most valuable habit in SAS.

Three kinds of messages

Prefix Meaning Typical action
NOTE: Information: what ran, how many rows Read; some notes are warnings in disguise
WARNING: Something may be wrong but SAS continued Investigate; fix before relying on results
ERROR: SAS could not do what you asked Fix; the step usually did not complete

In SAS Studio, errors are colored red, warnings green and notes blue, so you can scan quickly. Programs submitted in batch mode write the same messages to the .log file.

A healthy log

A DATA step that works prints notes in this style (your numbers will differ):

TEXT
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.COPY has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

The two lines you check are how many observations were read and how many the new data set has. If you expected the second to be smaller after filtering and it is not, your filter did not work.

Common beginner problems

Missing semicolon

SAS
data copy;
   set sashelp.class
run;

Without the semicolon after sashelp.class, SAS reads run as another data set name. The log shows messages such as ERROR: File WORK.RUN.DATA does not exist. and the step ends up reading the wrong thing. The error is reported where SAS got confused, which can be after the real mistake. If an error makes no sense, check the semicolon on the line before it.

Misspelled keyword

SAS
proc prnt data=sashelp.class;
run;

SAS answers with ERROR: Procedure PRNT not found. Typos in statements inside a step typically give ERROR 180-322: Statement is not valid or it is used out of proper order. or ERROR 22-322: Syntax error, expecting one of the following: .... The numbers are SAS error codes you can search for.

Misspelled data set or variable

SAS
proc print data=sashelp.clas;
run;

gives ERROR: File SASHELP.CLAS.DATA does not exist. A misspelled variable in a PROC step gives ERROR: Variable XYZ not found. In a DATA step, however, a misspelled variable is not an error at all. SAS creates a new numeric variable that is always missing and notes:

TEXT
NOTE: Variable agee is uninitialized.

That innocent-looking note is one of the most important to read. A step with an uninitialized variable almost always has a typo.

Invalid data

When SAS reads a value that does not fit the variable's type, it writes a NOTE: Invalid data for ... message, shows the offending line, and sets the value to missing. The step still finishes, so a quick glance at the output can miss it.

Unbalanced quotes

An unmatched quotation mark can make SAS treat the rest of the program as a string. The log may say WARNING: The quoted string currently being processed has become more than 262 characters long. The remedy is to fix the quote and resubmit; in some interfaces you must first clear the unfinished step.

Messages you may want to avoid

Some notes are valid but deserve attention:

  • NOTE: Missing values were generated as a result of performing an operation on missing values. Arithmetic with a missing value gives a missing result.
  • NOTE: Character values have been converted to numeric values at the places given by... SAS converted types automatically; do it yourself so you know it is intended.
  • WARNING: Multiple lengths were specified for the variable... The same variable was defined with different lengths.
  • NOTE: MERGE statement has more than one data set with repeats of BY values. A many-to-many merge, which rarely does what you want.

A review checklist

  1. Search the log for ERROR and WARNING. There should be none.
  2. Read the notes about uninitialized, invalid data, converted and repeats of BY values.
  3. Compare the observation counts with what you expect.
  4. Confirm that the output data sets have the expected number of variables.
  5. Clear the log before the final run, so you review only that run.

Experienced teams automate this with a log checker. The Python stand-in below does so in miniature (it is not SAS, and the log lines are made up).

Python Python stand-in: a tiny log scanner

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When a log has many errors, fix the first one and rerun. Later errors are often side effects of the first.

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a DATA step, a misspelled variable name on the right of an assignment usually produces:

    SAS creates a new variable that is always missing and writes NOTE: Variable ... is uninitialized.
  2. 2. A forgotten semicolon makes SAS:

    The following statement is absorbed into the previous one; the error message points to where SAS got confused.
  3. 3. Which log line confirms a filter worked as expected?

    Compare observations read with observations in the new data set.
  4. 4. With several errors in the log, what should you do?

    Later errors are frequently consequences of the first.

Summary

  • The log has NOTE, WARNING and ERROR messages; read it after every run.
  • Check the observation and variable counts of each step.
  • Uninitialized variables, invalid data, automatic type conversion and BY repeats are notes that often hide bugs.
  • A missing semicolon is the classic first mistake; fix the first error and rerun.

Next: Libraries and Data Sets