SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1758|回复: 6
打印 上一主题 下一主题

请教一道SAS base题目

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2011-6-22 00:59:30 | 只看该作者

请教一道SAS base题目

(123题#111)
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 dose the variable EXPERISE 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
理解不能啊为什么没有High?果然还是那个else句子出了问题?该怎么理解?
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2011-6-26 12:14:47 | 只看该作者

Re: 请教一道SAS base题目

if 3总是成立滴,SO不会到之后判断去了
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2011-6-28 08:17:01 | 只看该作者

Re: 请教一道SAS base题目

This question is as follow: You can see, the statement ' or 3' , it should be or' level=3'. So there is a mistake about this conditional statement, the SAS will stop here. When any observation to be read, it is stop here. Never continue, so you can see that the level=4, never be read by sas. That's it. I am not sure. Please refer to others opinions. Thanks.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2011-9-1 05:30:26 | 只看该作者

Re: 请教一道SAS base题目

如果把程序改为:

data work.expertise;
    set work.levels;
    if level = . then expertise = 'Unknown';
    else if level = 1 then expertise = 'Low';
    else if level = 2 or level = 3 then expertise = 'Medium'
    else expertise ='High';
run;

或者改为:
data work.expertise;
    set work.levels;
    if level = . then expertise = 'Unknown';
    else if level = 1 then expertise = 'Low';
    else if level = 2 then expertise = 'Medium';
    else if level = 3 then expertise = 'Medium';
    else expertise ='High';
run;

都能得到正确的结果。所以,程序的错误应该是出在 else if level = 2 or 3 then expertise = 'Medium' 这一句。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
5#
 楼主| 发表于 2011-9-12 00:18:40 | 只看该作者

Re: 请教一道SAS base题目

so the statement "or 3"is wrong
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
6#
 楼主| 发表于 2011-10-25 15:42:06 | 只看该作者

Re: 请教一道SAS base题目

level=2 or 3 等价于 (level=2) or (3)  故恒成立
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
7#
 楼主| 发表于 2011-12-13 10:34:27 | 只看该作者

Re: 请教一道SAS base题目

正如上面解释到的原因,在下学习了。
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-5-7 23:31 , Processed in 0.070465 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表