全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2514 5
2008-07-11

Questions:

1. 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 summited:
Data work.expertise;
set work.levels;
if level = . then expertise ="Unkown';
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

why no 'high'  and Burt 4 is evaluted to 'Medium' after run the result?

2. A frequency report of the variable Jobcode in the Work.Actors data set is listed
below.
Jobcode Frequency Percent Cumulative
Frequency Cumulative
Percent
Actor I   2  33.33  2  33.33
Actor II  2  33.33  4  66.67
Actor III 2  33.33  6  100.00

Frequency Missing = 1

The following SAS program is submitted:
data work.joblevels;
set work.actors;
if jobcode in ('Actor I', 'Actor II') then
   joblevel='Beginner';
if jobcode='Actor III' then
   joblevel='Advanced';
else joblevel='Unknown';
run;
Which of the following represents the possible values for the variable joblevel in the
Work.Joblevels data set?
a. Advanced and Unknown only
b. Beginner and Advanced only
c. Beginner, Advanced, and Unknown
d. ' ' (missing character value)

Answer A

Why no 'Beginner'? Please help to explain, thanks.

[此贴子已经被作者于2008-7-11 3:19:35编辑过]

二维码

扫码加我 拉你入群

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

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

全部回复
2008-7-11 20:10:00

The second one:

the first if-then statement is useless in this code, because the following if-then-else statement has a trash-bin else statement which puts everything other than 'advanced' to 'unkonwn'.

二维码

扫码加我 拉你入群

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

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

2008-7-11 20:15:00

The first One:

The key is to understand the following code:

if level = 2 or 3 then expertise = 'Medium';
The colored one is always true, because 3 is always greater than 1, therefore, regardless of the value of level, level = 2 or 3 is always '1' which is true. That makes everything to be 'medium'.

I didnot find out the answer at first place. I tried every possible codes in SAS, and finally found out the solution.

Thanks for your asking. It helps me too.

二维码

扫码加我 拉你入群

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

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

2008-7-11 21:57:00

Thank you for answering my question and you used smart way to get the solution for first one. Great Job!

I am still confusing a little about the second one. Suppose we put a "else" in the second if-than statment, then the result would include "Beginner"?  If this is true, it helps a lot to understand the question. If this true, so we could say, if we meet similar question we can do same thing and ignore the first if-then statment?

Thanks.

二维码

扫码加我 拉你入群

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

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

2008-7-12 02:45:00
To the second one:

The original code:
if jobcode in ('Actor I', 'Actor II') then joblevel='Beginner';
if jobcode='Actor III' then joblevel='Advanced';
else joblevel='Unknown';

In Data Step, after the first if-then statement, the second if-then statement still deal with the same observation. You are right, if you put 'else' before the second if-statement, you will keep the 'Beginner'.
二维码

扫码加我 拉你入群

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

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

2008-7-12 07:19:00
Thank you all guys, this helped a lot.
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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