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. My advice: 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 Section

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;

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 becomes 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 in 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 Section

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;

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 Section

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;

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.