Click on the Comments to view the Answers

Sunday, January 24, 2010

Base 13

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 

17 comments:

SASGuru said...

Answer B

This is a tricky question..

Notice this statement.

else if level = 2 or 3 then expertise = 'Medium';
it should have been level in (2,3) or level=2 or level=3.

surprisingly SAS does not throw an error….
It tries to evaluate the expression “level = 2 or 3”… It’s weird but I went ahead and tried the code…Look at the values of the Condition and Level in the Log below

data work.TEST;
infile cards;
input obs name $ level;
if level = . then expertise = 'Unknown';
else if level = 1 then expertise = 'Low';
else if level = 2 or 3 then expertise = 'Medium';
else expertise = 'High';
condition=(level = 2 or 3);

cards;
1 Frank 1
2 Joan 2
3 Sui 2
4 Jose 3
5 Burt 4
6 Kelly .
7 Juan 1
;
run;

obs=1 name=Frank level=1 expertise=Low condition=1 _ERROR_=0 _N_=1
obs=2 name=Joan level=2 expertise=Medium condition=1 _ERROR_=0 _N_=2
obs=3 name=Sui level=2 expertise=Medium condition=1 _ERROR_=0 _N_=3
obs=4 name=Jose level=3 expertise=Medium condition=1 _ERROR_=0 _N_=4
obs=5 name=Burt level=4 expertise=Medium condition=1 _ERROR_=0 _N_=5
obs=6 name=Kelly level=. expertise=Unknown condition=1 _ERROR_=0 _N_=6
obs=7 name=Juan level=1 expertise=Low condition=1 _ERROR_=0 _N_=7
NOTE: The data set WORK.TEST has 7 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds

Unknown said...

why isn't level =4 considered expertise = high?
why is it considered expertise = medium ?

Unknown said...

Ya the same doubt as deepika siad

SHREYASH said...

SHREYASH
yup the answer should be C

Kyle said...

The answer is B.

The 'or 3' part of the if statement is always considered true; non-zero values are always logically true, and 0 is always logically false. The else block never reaches 'High'.

onmysunnyside said...

data expertise;
infile datalines;
input name $ level;
if level = . then expertise = 'Unknown';
else if level = 1 then expertise = 'Low';
else if level = 2 or 3 then expertise = 'Medium';
else expertise = 'High';
datalines;
Frank 1
Joan 2
Sui 2
Jose 3
Burt 4
Kelly .
Juan 1
;
run;

111 data expertise;
112 infile datalines;
113 input name $ level;
114 if level = . then expertise = 'Unknown';
115 else if level = 1 then expertise = 'Low';
116 else if level = 2 or 3 then expertise = 'Medium';
117 else expertise = 'High';
118 datalines;

NOTE: The data set WORK.EXPERTISE has 7 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds


126 ;
127 run;
the expertise for Burt, 4 came as Medium......

Manna said...

Thank you Kyle for your expert suggestions (The 'or 3' part of the if statement is always considered true) that i think the trick of the question

Unknown said...

concur with B.
KYLE U ARE RIGHT.IT WILL ALWAYS BE TRUE.

neurosas said...

B.
To get 'C' below syntax may work.

data expertise;
set worklevel;
if level = . then expertise = 'Unknown';
else if level = 1 then expertise = 'Low';
else if level = 2 or 3 then expertise = 'Medium';
if level = 4 then expertise = 'High'; <----/* if you make last 'else if' to just 'if' it will read Burt expertise High as 4*/
run;

Unknown said...

I did not understand something.
With reference to what Kyle said,
if level = 2 or 3
in this statement, why only 'or 3' part is considered for non zero value being true.
2 is also a non zero value. It should directly display medium without even bothering to go to or 3 part!

Unknown said...

I added obs with y2k and level 0 and applied condition else if level = 0 then expertise = 'High';.

the result is "Medium". I'm learning SAS, pls help.

data work.expertise;
infile cards;
input name$ level;
if level = . then expertise = 'Unknown';
else if level = 1 then expertise = 'Low';
else if level = 2 or 3 then expertise = 'Medium';
else if level = 0 then expertise = 'High';
put _all_;
cards;
Frank 1
Joan 2
Sui 2
Jose 3
y2k 0
Burt 4
Kelly .
Juan 1
;
run;

name=Frank level=1 expertise=Low _ERROR_=0 _N_=1
name=Joan level=2 expertise=Medium _ERROR_=0 _N_=2
name=Sui level=2 expertise=Medium _ERROR_=0 _N_=3
name=Jose level=3 expertise=Medium _ERROR_=0 _N_=4
name=y2k level=0 expertise=Medium _ERROR_=0 _N_=5
name=Burt level=4 expertise=Medium _ERROR_=0 _N_=6
name=Kelly level=. expertise=Unknown _ERROR_=0 _N_=7
name=Juan level=1 expertise=Low _ERROR_=0 _N_=8
NOTE: The data set WORK.EXPERTISE has 8 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds

Unknown said...

91 data work.expertise;
92 infile datalines;
93 input name $ level;
94 if level = . then expertise = 'Unknown';
95 else if level = 1 then expertise = 'Low';
96 else if level = 2 or 3 then expertise = 'Medium';
97 else if level = 4 then expertise = 'High';put _all_;
98
99 datalines;
Frank 1
Joan 2
Sui 2
Jose 3
Burt 4
Kelly .
Juan 1
;


name=Frank level=1 expertise=Low _ERROR_=0 _N_=1
name=Joan level=2 expertise=Medium _ERROR_=0 _N_=2
name=Sui level=2 expertise=Medium _ERROR_=0 _N_=3
name=Jose level=3 expertise=Medium _ERROR_=0 _N_=4
name=Burt level=4 expertise=Medium _ERROR_=0 _N_=5
name=Kelly level=. expertise=Unknown _ERROR_=0 _N_=6
name=Juan level=1 expertise=Low _ERROR_=0 _N_=7

according to this code we get B. Low, Medium, and Unknown only

*********************
131 data work.expertise;
132 infile datalines;
133 input name $ level;
134 if level = . then expertise = 'Unknown';
135 else if level = 1 then expertise = 'Low';
136 else if level = 2 or level = 3 then expertise = 'Medium';
137 else if level = 4 then expertise = 'High';put _all_;
138
139 datalines;
Frank 1
Joan 2
Sui 2
Jose 3
Burt 4
Kelly .
Juan 1
;



name=Frank level=1 expertise=Low _ERROR_=0 _N_=1
name=Joan level=2 expertise=Medium _ERROR_=0 _N_=2
name=Sui level=2 expertise=Medium _ERROR_=0 _N_=3
name=Jose level=3 expertise=Medium _ERROR_=0 _N_=4
name=Burt level=4 expertise=High _ERROR_=0 _N_=5
name=Kelly level=. expertise=Unknown _ERROR_=0 _N_=6
name=Juan level=1 expertise=Low _ERROR_=0 _N_=7




or



151 data work.expertise;
152 infile datalines;
153 input name $ level;
154 if level = . then expertise = 'Unknown';
155 else if level = 1 then expertise = 'Low';
156 else if level = 2 or level = 3 then expertise = 'Medium';
157 else expertise = 'High';put _all_;
158
159 datalines;
Frank 1
Joan 2
Sui 2
Jose 3
Burt 4
Kelly .
Juan 1
;

name=Frank level=1 expertise=Low _ERROR_=0 _N_=1
name=Joan level=2 expertise=Medium _ERROR_=0 _N_=2
name=Sui level=2 expertise=Medium _ERROR_=0 _N_=3
name=Jose level=3 expertise=Medium _ERROR_=0 _N_=4
name=Burt level=4 expertise=High _ERROR_=0 _N_=5
name=Kelly level=. expertise=Unknown _ERROR_=0 _N_=6
name=Juan level=1 expertise=Low _ERROR_=0 _N_=7


then we get : C. Low, Medium, High, and Unknown only

Unknown said...

are these Base or Advanced Exam questions ?

H. C. said...

B

Unknown said...

What Kyle said is absolutely correct.

Nitin Paighowal said...

Its B because any number other than zero or missing is considered "TRUE" so condition "2 or 3" is always true whenever SAS searches for IF condition for number 2,3 and 4. Since "2 or 3" condition becomes true it never let SAS to execute statements under it.

Anonymous said...

I have found that if I change else if level IN(2,3) then expertise = 'Medium' to
else if level in(2,3) then expertise = 'Medium'; I do in fact get the expertise level of 3.
Any thoughts. So is there actually a wrong answer to this question or should I say right answer.

Post a Comment



Technology Top Blogs On our way to 1,000,000 rss feeds - millionrss.com Hihera.com Blog Directory - OnToplist.com blogarama - the blog directory Blog Directory
Disclaimer

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.

Other brand and product names are trademarks of their respective companies.

This blog is not responsible for any kind of copyright violation. This blog just collects the links hosted or posted by other servers/people/search engines.The creator of this page or the ISP(s) hosting any content on this site take no responsibility for the way you use the information provided on this site.If anybody has any copyright claim on it and doesn’t wish the information provided to be shown on our site, please do respond to this email. We shall remove them off immediately. Any inconvenience is regretted. Please do mention your exact grievance/problems with respect to certain third party links. We assure you that appropriate action will be taken off. Thank you