Ch 5: Identifying and Correcting SAS Language Errors Flashcards
Suppose you have submitted a SAS program that contains spelling errors. Which set of steps should you perform, in the order shown, to revise and resubmit the program? a. • Correct the errors. • Clear the SAS log. • Resubmit the program. • Check the Output window. • Check the SAS log. b. • Correct the errors. • Resubmit the program. • Check the Output window. c. • Correct the errors. • Clear the SAS log. • Resubmit the program. • Check the Output window. d. • Correct the errors. • Clear the Outputwindow. • Resubmit the program. • Check the Output window.
Correct answer: a
To correct errors in programs when you use the Editor window, you usually need to recall the submitted statements from the recall buffer to the Editor window. After correcting the errors, you can resubmit the revised program. However, before doing so, it is a good idea to clear the messages from the SAS log so that you do not confuse the old error messages with the new messages. Remember to check the SAS log again to verify that your program ran correctly.
What happens if you submit the following program?
proc sort data=cert.stress out=maxrates;
by maxhr;
run;
proc print data=maxrates label double noobs;
label rechr=’Recovery Heart Rate;
var resthr maxhr rechr date;
where toler=’I’ and resthr>90;
sum fee;
run;
a.
SAS log messages indicate that the program ran successfully.
b.
A log message might indicate an error in a statement that seems to be valid.
c.
A SAS log message indicates that an option is not valid or not recognized.
d.
A SAS log message might indicate that a quoted string has become too long or that the statement is ambiguous.
Correct answer: d
The missing quotation mark in the LABEL statement causes SAS to misinterpret the statements in the program. When you submit the program, SAS is unable to resolve the PROC step, and a PROC PRINT running message appears at the top of the active window.
What generally happens when a syntax error is detected?
a.
SAS continues processing the step.
b.
SAS continues to process the step, and the SAS log displays messages about the error.
c.
SAS stops processing the step in which the error occurred, and the SAS log displays messages about the error.
d.
SAS stops processing the step in which the error occurred, and the Output window displays messages about the error.
Correct answer: c
Syntax errors generally cause SAS to stop processing the step in which the error occurred. When a program that contains an error is submitted, messages regarding the problem also appear in the SAS log. When a syntax error is detected, the SAS log displays the word ERROR, identifies the possible location of the error, and gives an explanation of the error.
A syntax error occurs during the following actions:
a.
Some data values are not appropriate for the SAS statements that are specified in a program.
b.
The code executes successfully, but produces incorrect results.
c.
Program statements do not conform to the rules of the SAS language.
d.
none of the above
Correct answer: c
Syntax errors occur because the program statements did not conform to the rules of the SAS language. Syntax errors, such as misspelled keywords, generally prevent SAS from executing the step in which the error occurred
How can you tell whether you have specified an invalid option in a SAS program?
a.
A SAS log message indicates an error in a statement that seems to be valid.
b.
A SAS log message indicates that an option is not valid or not recognized.
c.
You cannot tell until you view the output from the program.
d.
none of the above
Correct answer: b
When you submit a SAS statement that contains an invalid option, a log message notifies you that the option is not valid or not recognized. You should recall the program, remove or replace the invalid option, check your statement syntax as needed, and resubmit the corrected program.
Which of the following programs contains a syntax error? a. proc sort data=cert.mysales; by region; run; b. dat=work.mysales; set cert.sales17; where sales<5000; run; c. proc print data=work.mysales label; label region='Sales Region'; run; d. none of the above
Correct answer: b
The DATA step contains a misspelled keyword (dat instead of data). However, this is such a common (and easily interpretable) error that SAS produces only a warning message, not an error.
What are the temporary variables that can be helpful when debugging a DATA step? a. OBS b. _N_ c. _ERROR_ d. b and c only
Correct answer: d
The N and ERROR temporary variables can be helpful when debugging a DATA step. The N variable displays debugging messages for a specified number of iterations of the DATA step. The ERROR displays debugging messages when an error occurs.
When the source of the errors in the program is not apparent, which statement or statements can you use to examine errors and print messages to the log? a. PUTLOG statement b. PUT statement c. VAR statement d. a and b only e. none of the above
Correct answer: d
You can use the PUTLOG statement or the PUT statement to help identify errors and print messages in the SAS log. You can use the PUTLOG statement in a DATA step to write messages to the SAS log to help identify logic errors. You can also use temporary variables in the PUTLOG to assist in debugging. You can use the PUT statement to examine variables and print your own message to the SAS log.
What types of errors can the PUTLOG statement help you resolve? a. syntax errors b. semantic errors c. logic errors d. all of the above
Correct answer: c
A logic error occurs when the program statements follow the rules and execute, but the results are not correct. You can use the PUTLOG statement in the DATA step to help identify logic errors.