UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Class Notes 2.0
The Errors of Your Ways


1.0 Introduction

This unit will look at common errors in writing SAS programs and the symptoms (error messages in the SAS Log) that the errors cause. Then, when you see these error messages in the future, you will be familiar with the cause and how to fix it. 

1.1 About the data

We will be using the hs1 file we have been using. 

2. Examples of errors

2.1 The missing semicolon

This is the most common error, and we all make it.  Here is an example.

PROC PRINT DATA='c:\sas\hs1';
  VAR read write math
RUN;

When we run this, we don't get any output in the output window, and the log window says.

6    PROC PRINT DATA='c:\sas\hs1' ;
7      VAR read write math
8    RUN;
ERROR: Variable RUN not found.

Note that the semicolon is missing after math, so SAS thinks that RUN is another variable that we want to print.  Since RUN is not a variable in our data file, it says ERROR: Variable RUN not found.  We can fix this by putting in the semi-colon as shown below.  This will then run fine.

PROC PRINT DATA='c:\sas\hs1' ;
  VAR read write math ;
RUN;

2.2 Misspellings in a PROC STEP

Misspelling Variables

Another common problem is misspelling variable names.  Consider the example below where we misspelled math as mat .

PROC PRINT DATA='c:\sas\hs1' ;
  VAR read write mat ;
RUN;

When we run this, we get the error message below telling us that it could not find the variable mat.

1   PROC PRINT DATA='c:\sas\hs1' ;
22     VAR read write mat ;
ERROR: Variable MAT not found.
23   RUN;

We can fix the misspelling as shown below and this will work fine.

PROC PRINT DATA='c:\sas\hs1' ;
  VAR read write math ;
RUN;

Misspelling the data file name

Another common problem is misspelling the name of your data file, as shown in the example below where we put hs11 instead of hs1.

PROC PRINT DATA='c:\sas\hs11' ;
  VAR read write math ;
RUN;

When we run this, we get the error message below telling us that it could not find the variable mat.

24   PROC PRINT DATA=hs11 ;
ERROR: File does not exist.
25     VAR read write mat ;
26   RUN;

We can fix the misspelling as shown below and this will work fine.

PROC PRINT DATA='c:\sas\hs1' ;
  VAR read write math ;
RUN;

Mispelling SAS keywords

Another common problem is misspelling SAS keywords.  Below we typed DAT='c:\sas\hs1' instead of DATA='c:\sas\hs1'.

PROC PRINT DAT='c:\sas\hs1' ;
  VAR read write math ;
RUN;

When we run this, we get the following message in the log.  What do you know, SAS figured out the misspelling and told us that it assumed that we meant DATA= and went ahead and ran the PROC PRINT.  You can see the results in the output window.

48   PROC PRINT DAT='c:\sas\hs1';
                ---
                1
WARNING 1-322: Assuming the symbol DATA was misspelled as DAT.
49     VAR read write math ;
50   RUN;

NOTE: There were 200 observations read from the data set....
NOTE: PROCEDURE PRINT used:
      real time           0.47 seconds
      cpu time            0.04 seconds

Nevertheless, we still want to fix this misspelling as shown below.

PROC PRINT DATA='c:\sas\hs1' ;
  VAR read write math ;
RUN;

2.3 Using the wrong SAS keyword in a PROC STEP

Another common problem is using the wrong SAS keyword.  Below we typed VAR instead of TABLES in the PROC FREQ statement.

PROC FREQ DATA='c:\sas\hs1' ;
  VAR read write math ;
RUN;

When we run this, we get the following message in the log. SAS is telling us that it does not understand the use of VAR since that is not a valid statement with with PROC FREQ

51   PROC FREQ DATA='c:\sas\hs1';
NOTE: SCL source line.
52     VAR read write math ;
       ---
       180
ERROR 180-322: Statement is not valid or it is used out of proper order.
53   RUN;

We can change the VAR to TABLES and this will work fine.

PROC FREQ DATA='c:\sas\hs1' ;
  TABLES read write math ;
RUN;

3.0 For more information


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California