Debugging Errors [1-5]


Syntax Error

A syntax error is a common SAS programming error.

It happens when the code includes incorrect syntax.

Below are some examples:

  • Spelling error
  • Missing semi-colon
  • Unbalanced quotes

Let's look at each type of error in detail.

​Spelling Error

Spelling errors happen when a SAS keyword is misspelled.

Below is an example:

proc freqx;
table make;

The FREQ procedure above is misspelled as FREQX.

​When you run the program, you will see the following error message in the log:

Spelling errors can be identified in the SAS log.

Simply review the error message on the SAS log and then correct the spelling error.

Missing Semi-colon Error

In SAS, each statement ends with a semi-colon. 

Running the following statement without a semi-colon will cause an error:

proc freq
table make;

In the above example, we are missing the semi-colon at the end of the PROC FREQ statement:

What will happen if you omit the semi-colon?

SAS will treat the first and second line of your code as a single statement:

Essentially, you are running the code below:

SAS will treat the keyword "table" and "make" as options of the Proc Freq statement (similar to the NOPRINT, KEEP and DROP options).

Since TABLE and MAKE are not valid options for Proc Freq, SAS will generate an invalid option error on the SAS log:

ERROR 22-322: Syntax error, expecting one of the following: ;, (, COMPRESS, DATA, FC, FORMCHAR, NLEVELS, NOPRINT, ORDER, PAGE.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

When you see such error messages, you should check if you have:

  • A missing semi-colon or
  • An invalid option

​We will look at the invalid options error shortly.

Unbalanced Quote

An unbalanced quote is another common error in SAS.

It happens when you miss a quotation mark when assigning character values (e.g. var1 = "ABC ;).

You can identify such errors by the unusual color pattern of the code.

Let's look at an example:

data test;
a = "ABC;
b = 123

Copy and paste the code into the SAS editor.

You can can see that something is wrong by the color of the code:

In SAS, the character values within the quotation change to purple.

If any part of your code (not values) changes to purple, this indicates there is a missing quotation.

Let's add the missing quote back to the code:

data test;
a = "ABC";
b = 123

The colors now look normal.

Now, none of the code is purple, except for the literal character values.


Copy and run the code below in SAS:

What kind of errors can you identify from the code above?

Please provide the correct code.

Need some help?

Get Hint

Get Solution