Given the following raw data records in DATAFILE.TXT:
----|----10---|----20---|----30
Kim,Basketball,Golf,Tennis
Bill,Football
Tracy,Soccer,Track
The following program is submitted:
data WORK.SPORTS_INFO;
length Fname Sport1-Sport3 $ 10;
infile ‘DATAFILE.TXT’ dlm=’,’;
input Fname $ Sport1 $ Sport2 $ Sport3 $;
run;
proc print data=WORK.SPORTS_INFO;
run;
Which output is correct based on the submitted program?
A.
Obs |
Fname |
Sport1 |
Sport2 |
Sport3 |
1 |
Kim |
Basketball |
Golf |
Tennis |
2 |
Bill |
Football |
|
|
3 |
Tracy |
Soccer |
Track |
|
B.
Obs |
Fname |
Sport1 |
Sport2 |
Sport3 |
1 |
Kim |
Basketball |
Golf |
Tennis |
2 |
Bill |
Football |
Football |
Football |
3 |
Tracy |
Soccer |
Track |
Track |
C.
Obs |
Fname |
Sport1 |
Sport2 |
Sport3 |
1 |
Kim |
Basketball |
Golf |
Tennis |
2 |
Bill |
Football |
Tracy |
Soccer |
D.
Obs |
Fname |
Sport1 |
Sport2 |
Sport3 |
1 |
Kim |
Basketball |
Golf |
Tennis |
2 |
Bill |
Football |
|
|
Check AnswerHide AnswerAnswer: C
注解:当一行数据中变量值的数量少于变量的数量时,SAS会去下一行接着读取数据。当所有变量都得到赋值之后,无论该行数据中是否还有未使用的变量值,SAS都会前往下一行开始新的DATA step,即开始读取新的观测值。所以在题目中,当SAS在执行第二次DATA step时,由于第二行数据只有2个值,SAS会去第三行寻找值并赋给Sport2和Sport3。当4个变量都得到赋值之后,SAS忽略第三行中余下的值Track。如果这时DATAFILE.TXT中还有第四行的话,SAS就会前往第四行开始读取第三个观测值。如果要得到A中的结果,在INFILE statement末尾加上MISSOVER即可。DLM和MISSOVER具体的含义请查看SAS Base (2)。