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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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