SAS中文论坛

标题: 请教个BASE问题 [打印本页]

作者: shiyiming    时间: 2011-1-30 18:44
标题: 请教个BASE问题
The contents of the raw data file are listed below:
----|----10----|----20----|----30
Ruth 39 11
Jose 32 22
Sue 30 33
John 40 44

The following SAS program is submitted:
data test;
infile 'employee';
input employee_name $ 1-4;
if employee_name='Sue' then input age 7-8;
else input idnum 10-11;
run;
Which one of the following values does the variable AGE contain when the name of the employee is 'Sue'?

答案: 40

请问为什么不是30?我觉得input employee_name $ 1-4; 后应该有个@才对,因此答案应是 ...(missing numeric value)
作者: shiyiming    时间: 2011-1-30 20:53
标题: Re: 请教个BASE问题
"input employee_name $ 1-4;"之后转到了下一个观测行进行input,所以答案是40,这是结果中只有ruth和sue两个观测行。
如果是"input employee_name $ 1-4 @;",进行下一个input时则保持在同一观测行,这时结果输出4条观测,sue的age是30。
作者: shiyiming    时间: 2012-3-11 13:08
标题: Re: 请教个BASE问题
呵呵,这个解释不太听得懂啊???
作者: shiyiming    时间: 2012-3-11 14:30
标题: Re: 请教个BASE问题
假设这是SAS代码:
data a;
input name $ 1-4 ;
if name='Sue' then input age 6-7 ;
else input id  9-10;
datalines;
Ruth 39 11
Jose 32 22
Sue  30 33
John 40 44
;
run;
首先读入Ruth作为name的值。由于name的值不是Sue,则从下一行输入id,其值22,也就是列输入的位置。此时,第一个观测读写完成。对于Sue,从下一行的指定列读入age,为40,id由于没有赋值则为缺失值。出现一个input,则会往下移动一行,故Jose那一行就只读了个id的值。所以最后的数据集只有两行,结果为,
name  age  id
Ruth   .       22
Sue     40     .




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2