Debugging Errors [2-5]


Syntax Error II

In this section, we will look at two additional syntax errors in SAS:

  • Missing RUN/QUIT Statement
  • Invalid Options Error

​Missing RUN/QUIT Statement

A RUN or QUIT statement is used to end a data step or proc step.

data test;
a = 1;

proc sql;
select *

The RUN or QUIT statement is a signal to SAS that it is the end of the step.

However, we don't always have to end the step with a RUN or QUIT statement. 

​Let's look at an example.

data test;
a = 1;

proc print data=test;

In this example, there is no RUN statement at the end of the data step:

The code above runs perfectly.

The data set TEST is created and displayed in the Results Viewer:

Why isn't there an error or warning message?

It turns out that you do not have to specify the RUN or QUIT statement when you start a new data step or proc step immediately after.

For example, we have the Proc Print step right after the data step:

The start of the proc step signals the end of the previous data step.

The RUN statement is not required, and as a result, no error or warning message is generated in the SAS log.

Let's look at one more example:

data test;
a = 1;

The data step above does not end with a RUN statement. 

However, there is no proc step that follows.

Does the code above give you an error?

The answer is, it depends on which software you are using.

If you are using SAS EG or SAS Studio, you are totally fine.

This software automatically adds a RUN statement at the end of the program before compiling it.

However, if you are using SAS 9.4, you will see an error message in the SAS log.

Invalid Option Error

​An invalid option error happens when you use an option that's not valid for a particular statement.

Let's look at some examples.

proc print xlabel;

In this example, we added an invalid option, "XLABEL", to the Proc Print procedure.

XLABEL is not a valid option for Proc Print, so SAS would not understand how to interpret the option.

As a result, an error message is generated in the SAS log:

ERROR 22-322: Syntax error, expecting one of the following: ;, (, BLANKLINE, CONTENTS, DATA, DOUBLE, GRANDTOTAL_LABEL,

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

These error messages are similar to those we saw in the last section.

They tell you SAS is expecting other syntax or options, such as:

  • ;
  • (
  • DATA
  • ...etc.

and the one we specified (i.e. XLABEL) is not valid.

Programming Tip 2

As mentioned in the last section, a missing semi-colon can also cause an invalid option error message to be written to the SAS log.

When you encounter such an error message, check whether you have:
- An invalid option specified or
- A missing semi-colon in the statement.

Let's look at another example.

data cars (keep make model msrp);

In this Data step, the KEEP option was not specified correctly.

When using the KEEP option on a Data statement, it should be specified as:

keep=make model msrp

The equal sign (=) is missing in our code:

This will also cause an error message to be written to the SAS log:


In the last two sections, you have learned five common syntax errors. 

Below is a summary of each error and how you can identify them in the code:


Copy and run the code below in SAS:

data cars;
keep = make model msrp;

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

Please provide the correct code.

Need some help?

Get Hint

Get Solution