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!
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.
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'.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.