全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1616 4
2009-03-06

在准备SAS BASE的考试, 做123时遇到的这道题, 怎么想都想不通为什么答案是B而不是C. 请高手指点一下.

A SAS PRINT procedure output of the WORK.LEVELS data set is listed
> below:
> Obs name level
> 1 Frank 1
> 2 Joan 2
> 3 Sui 2
> 4 Jose 3
> 5 Burt 4
> 6 Kelly .
> 7 Juan 1
> The following SAS program is submitted:
> data work.expertise;
> set work.levels;
> if level = . then
> expertise = 'Unknown';
> else if level = 1 then
> expertise = 'Low';
> else if level = 2 or 3 then
> expertise = 'Medium';
> else
> expertise = 'High';
> run;
> Which of the following values does the variable EXPERTISE contain?
> A. Low, Medium, and High only
> B. Low, Medium, and Unknown only
> C. Low, Medium, High, and Unknown only
> D. Low, Medium, High, Unknown, and ' ' (missing character value)
> Answer: B

二维码

扫码加我 拉你入群

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

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

全部回复
2009-3-6 04:41:00

else if level = 2 or 3  then
should be
else if level = 2 or level= 3  then

[此贴子已经被作者于2009-3-6 4:44:32编辑过]

二维码

扫码加我 拉你入群

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

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

2009-3-6 10:16:00

这是考阅读,不是考编程

二维码

扫码加我 拉你入群

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

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

2009-3-6 13:28:00

这道题考了两点:
1。if 语句中的 or 和 and 的前后应该是两个条件。每一个条件为 true 时 return 1, 为 false 时 return 0。
 if level = 2 or 3 then 语句中 or 后面 的 3 is a constant and >0 所以 always 为 ture。

2。 if, else if 中条件判断的次序。
 if level = . then  expertise = 'Unknown';
 else if level = 1 then expertise = 'Low';
 else if level = 2 or 3 then  expertise = 'Medium';
试着把上面的else if 的次序换一下,再看看结果就明白了。
 if level = . then  expertise = 'Unknown';
 else if level = 2 or 3 then  expertise = 'Medium';
 else if level = 1 then expertise = 'Low';

[此贴子已经被作者于2009-3-6 13:34:58编辑过]

二维码

扫码加我 拉你入群

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

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

2009-3-7 03:07:00

"if level=2 or 3" means if level=2 or if 3, so this condition is always true, anything comes after it and does not meet all the previous conditions will be resolved to 'Medium'. If you put it on top you will only get one result for all the observations: 'Medium'.

二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群