Solved
Contributor
Posts: 32

# else if

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!

Accepted Solutions
Solution
‎02-25-2016 02:27 PM
Posts: 3,167

## Re: else if

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.

All Replies
Posts: 3,167

## Re: else if

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'.

Contributor
Posts: 32

## Re: else if

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.
Solution
‎02-25-2016 02:27 PM
Posts: 3,167

## Re: else if

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.

Contributor
Posts: 32

## Re: else if

Oh great! Now I exactly understood this. Thanks a ton @Haikuo for your answers
🔒 This topic is solved and locked.