BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bulleride
Obsidian | Level 7

QUESTION 111 A SAS PRINT procedure output of the WORK.LEVELS data set is listed below: Obsname 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)

 

Ans –B

 

Why not like this:

 

.    then 'unknown'

1   then 'low'

0   then 'high'

any other   then 'medium'

 

as medium will always be true!

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

In this case, Medium is always true regardless what value is. If you put this

if level = 2 or 3 then expertise =' Medium';

on top of other conditions, then "Medium" is the only value you end up with.

 

 

It is the possition (3rd) of this always-true statement that gives missing value and '1' a chance to sneak in.

View solution in original post

4 REPLIES 4
Haikuo
Onyx | Level 15

The key is this one:

 else if level = 2 or 3 then expertise =' Medium';

Which is equivalent to this one:

 

 else if (level = 2) or (3) then expertise =' Medium';

Furthermore equivalent to this one:

 

 else if 3 then expertise =' Medium';

You can see by now: it is alway true. So besides the 'ifs' before this one (unknown/low), it only gets 'medium'.

 

Bulleride
Obsidian | Level 7
Why not the below reason @Haikuo?
Medium will always be true if the value is non zero (false) or missing (again false) and hence answer should be Unknown (for .), High (for 0) and else in every case Medium.
Haikuo
Onyx | Level 15

In this case, Medium is always true regardless what value is. If you put this

if level = 2 or 3 then expertise =' Medium';

on top of other conditions, then "Medium" is the only value you end up with.

 

 

It is the possition (3rd) of this always-true statement that gives missing value and '1' a chance to sneak in.

Bulleride
Obsidian | Level 7
Oh great! Now I exactly understood this. Thanks a ton @Haikuo for your answers 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2697 views
  • 3 likes
  • 2 in conversation