楼主: wangzhuo422
6047 4

[问答] 求教123的109题,为什么是40啊? [推广有奖]

  • 0关注
  • 1粉丝

大专生

31%

还不是VIP/贵宾

-

威望
0
论坛币
1135 个
通用积分
0.0600
学术水平
1 点
热心指数
1 点
信用等级
0 点
经验
413 点
帖子
43
精华
0
在线时间
25 小时
注册时间
2010-1-17
最后登录
2019-1-30

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
The contents of the raw data file EMPLOYEE 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;
in file' 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"?
A. 30
B. 33
C. 40
D. . (missing numeric value)
Answer: C

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:following Employee Variable contents Content following contents employee contain values

沙发
Eternal0601 发表于 2013-3-4 14:32:43 |只看作者 |坛友微信交流群
data test;
infile datalines;
input employee_name $ 1-4;
if employee_name = 'Sue' then input age 7-8;
else input idnum 10-11;
datalines;
Ruth  39 11
Jose  32 22
Sue   30 33
John  40 44
;
run;
上面这段code跟你这道题目本质是一样的,这里是用到的是column input,读到第一行时,employee_name=“Ruth”而不是“Sue”,故执行 input idnum 10-11语句,由于又遇到了input,指针实际已经跳到下一行了,也就是Jose这一行,将column10-11的22赋值给idnum,而age却没有赋值,就为空值

后面的类似循环,所以test中实际上只有两条记录,当employee_name=“Sue”时age为40,而idnum为空值

使用道具

藤椅
PhoenixHuang 发表于 2013-3-4 21:54:21 |只看作者 |坛友微信交流群
在input employee_name $ 1-4;后面没有@, 因此在读入第一行的1-4列后,employee_name=“Ruth”, 而数据指针已经移动到第二行了. 此时employee_name 不等于 'Sue', 因此对第二行执行 input idnum 10-11, 使idnum=22, 第一个观测结束读取.
第二个观测从第三行开始读取, 读取后 employee_name='Sue', 同样因为没有@,  数据指针移动到第四行. 此时因为employee_name 等于 'Sue', 因此对第四行数据执行 input age 7-8, 使age=40.
此题主要考数据指针的移动, 有无结尾@的区别.

使用道具

板凳
wangzhuo422 发表于 2013-3-4 23:43:35 |只看作者 |坛友微信交流群
PhoenixHuang 发表于 2013-3-4 21:54
在input employee_name $ 1-4;后面没有@, 因此在读入第一行的1-4列后,employee_name=“Ruth”, 而数据指针已 ...
那是说明因为这里面用了if, 所以有没有@会影响结果吗?

使用道具

报纸
PhoenixHuang 发表于 2013-3-5 09:32:02 |只看作者 |坛友微信交流群
wangzhuo422 发表于 2013-3-4 23:43
那是说明因为这里面用了if, 所以有没有@会影响结果吗?
加一个@, 结果完全不一样. 加了@后,  这题的答案就是30

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-29 01:46