SAS Base (30)

You’re attempting to read a raw data file and you see the following messages displayed in the SAS Log:

NOTE: Invalid data for Salary in line 4 15-23.
RULE:     ----|----10---|----20---|----30---|----40---|----50-
4         120104   F    46#30     11MAY1954 33
Employee_Id=120104 employee_gender=F Salary=. birth_date=-2061 _ERROR_=1 _N_=4
NOTE: 20 records were read from the infile ‘c:employees.dat’.
      The minimum record length was 33.
      The maximum record length was 33.
NOTE: The data set WORK.EMPLOYEES has 20 observations and 4 variables.

What does it mean?
A. A compiler error, triggered by an invalid character for the variable Salary.
B. An execution error, triggered by an invalid character for the variable Salary.
C. The 1st of potentially many errors, this one occurring on the 4th observation.
D. An error on the INPUT statement specification for reading the variable Salary.

Check Answer
Answer: B

注解:Compiler error是指SAS在编译代码时出错,例如代码写错了。Execution error是指代码没错,但是在执行代码是发生错误,例如试图将字符复制给数值型变量。本题中Salary是一个数值型变量,但46#30不是一个数值,所以出现错误。由于程序发生的是Execution error,数据依然会输出并建立data set,Salary的值为missing。例如一下程序:
data execution_error;
input Num1 Num2;
datalines;
1 2#3
3 4
;
run;
生成的data set为:

Obs Num1 Num2
1 1 .
2 3 4

如果是Compiler error,就不会建立新data set,例如以下例子,INPUT statement末尾漏了一个分号:
data compiler_error;
input Num1 Num2
datalines;
1 2
3 4
;
run;

具体的SAS错误类型请参考官方手册

Leave a Reply

Your email address will not be published. Required fields are marked *