8.1 - Missing Semicolons

8.1 - Missing Semicolons

This section illustrates the kinds of messages you might see in the log window when you've forgotten to put a semicolon at the end of a SAS statement. When your SAS program won't run, and you have ERROR messages appearing in your log window, check to see if you are missing a semicolon somewhere in the statements immediately preceding the location where you are getting the error message.

Example 8.1

The following program is missing a semicolon on the comment statement just before the DATA statement:

OPTIONS PS = 58 LS = 72 NODATE NONUMBER;
*Read in the trees data set
DATA trees;
    input type $ 1-16 circ_in hght_ft crown_ft;
	DATALINES;
oak, black        222 105 112
hemlock, eastern  149 138  52
ash, white        258  80  70
cherry, black     187  91  75
maple, red        210  99  74
elm, american     229 127 104
;
RUN;

   OPTIONS PS = 58 LS = 72 NODATE NONUMBER;
   *Read in the trees data set
   DATA trees;
       input type $ 1-16 circ_in hght_ft crown_ft;
       -----
       180

ERROR 180-322: Statement is not valid or it is used out of proper order.

       DATALINES;
       ---------
       180

ERROR 180-322: Statement is not valid or it is used out of proper order.

   oak, black        222 105 112
   ---
   180
ERROR 180-322: Statement is not valid or it is used out of proper order.

   hemlock, eastern  149 138  52
   ash, white        258  80  70
   cherry, black     187  91  75
   maple, red        210  99  74
   elm, american     229 127 104
   ;

   RUN;

When you omit a semicolon, SAS reads the statement that lacks the semicolon, plus the following statement, as one long statement. In this case, DATA trees become a part of the comment statement. Therefore, SAS thinks that the program doesn't contain a DATA statement. Therefore, SAS underlines the INPUT keyword and complains that it doesn't appear as a valid part of a SAS program. Launch and run  the SAS program, and review the contents of the log window to see the message that submitting such a program causes.

Example 8.2

This example shows the same program as above, but now the semicolon is missing at the end of the DATA statement:

OPTIONS PS = 58 LS = 72 NODATE NONUMBER;
  *Read in the trees data set;
  DATA trees
    input type $ 1-16 circ_in hght_ft crown_ft;
	DATALINES;
oak, black        222 105 112
hemlock, eastern  149 138  52
ash, white        258  80  70
cherry, black     187  91  75
maple, red        210  99  74
elm, american     229 127 104
;
RUN;

   OPTIONS PS = 58 LS = 72 NODATE NONUMBER;
   *Read in the trees data set;
   DATA trees
       input type $ 1-16 circ_in hght_ft crown_ft;
                  -
                  22
                  200
                    -
                    22
                    76
ERROR 22-322: Syntax error, expecting one of the following: a name,
              a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

       DATALINES;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

   ;


   RUN;

In this case, the INPUT statement becomes a part of the DATA statement. Therefore, SAS expects to see valid data set names or options, not a dollar sign ($) or column numbers. Launch and run  the SAS program, and review the contents of the log window to see the message that submitting such a program causes. You should see that SAS reports that it found a syntax error, and then goes on to tell you what it expected to find in the DATA statement.

Example 8.3

The next example shows the same program as above, in which the semicolon is missing at the end of the DATA statement. However, now the DATASTMTCHK system option has been added to the code:

OPTIONS DATASTMTCHK = ALLKEYWORDS;
*Read in the trees data set;
DATA trees
    input type $ 1-16 circ_in hght_ft crown_ft;
	DATALINES;
oak, black        222 105 112
hemlock, eastern  149 138  52
ash, white        258  80  70
cherry, black     187  91  75
maple, red        210  99  74
elm, american     229 127 104
;
RUN;

   OPTIONS DATASTMTCHK = ALLKEYWORDS;
   *Read in the trees data set;
   DATA trees
       input type $ 1-16 circ_in hght_ft crown_ft;
       -----      -
       57         22
                  200
                    -
                    22
                    76
ERROR 57-185: INPUT is not allowed in the DATA statement when option
              DATASTMTCHK=ALLKEYWORDS.  Check for a missing semicolon
              in the DATA statement, or use DATASTMTCHK=NONE.

ERROR 22-322: Syntax error, expecting one of the following: a name,
              a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

       DATALINES;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

   ;

   RUN;

The DATASTMTCHK system option controls what names you can use for SAS data sets in a DATA statement. By default, the option is set so that you cannot use the words MERGE, RETAIN, SET, or UPDATE as a SAS data set name. You can instead make all SAS keywords invalid SAS data set names by setting the DATASTMTCHK option to ALLKEYWORDS, as is done in the above program. Launch and run  the SAS program, and review the log window to see the message SAS displays when the DATASTMTCHK option is invoked.

We've looked at three examples now in which a semicolon is missing. Do you think it is fair to say that the moral of the story is that you can usually find the statement that lacks the semicolon by working backwards in your program starting with the keywords that are underscored in the error message? Once you've found the location where the semicolon is missing, simply add a semicolon, resubmit your corrected program, and check the SAS log again to make sure that there are no other errors.


Legend
[1]Link
Has Tooltip/Popover
 Toggleable Visibility