Solved
Contributor
Posts: 27

# Base Certification

Got this question on base sas certification prep.The answer is Expertise has only 3 values LOW,MEDIUM UNKNOWN ONLY.The level value  4 was also assigned Medium .Why??Can anyone help me here!!Thanks.

data temp;

input name \$ level;

datalines;

Frank 1

Joan 2

Sui 2

Jose 3

Burt 4

Kelly .

Juan 1

;

run;

data work.expertise;

set temp;

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;

Accepted Solutions
Solution
‎03-26-2015 06:59 PM
Super User
Posts: 13,523

## Re: Base Certification

The key bit is this line

else if level=2 or 3 then

Note that it does NOT say level = 3. computers only do what the syntax says and the construct is missing the qualification that LEVEL = 3. SAS interprets any non-zero value as "true" . So 3 is true. level=2 is false for a value of 4 for level but the OR true means that is where the value of Medium is assigned due to the previous ELSE constructs and the True value for 3.

Run this simple program:

data _null_;

if 3 then put "True";

else put 'False';

run;

and examine the log.

To get the likely intended result with the code use either

If level=2 or level=3 then ...

or

if level in (2,3) then ...

All Replies
Solution
‎03-26-2015 06:59 PM
Super User
Posts: 13,523

## Re: Base Certification

The key bit is this line

else if level=2 or 3 then

Note that it does NOT say level = 3. computers only do what the syntax says and the construct is missing the qualification that LEVEL = 3. SAS interprets any non-zero value as "true" . So 3 is true. level=2 is false for a value of 4 for level but the OR true means that is where the value of Medium is assigned due to the previous ELSE constructs and the True value for 3.

Run this simple program:

data _null_;

if 3 then put "True";

else put 'False';

run;

and examine the log.

To get the likely intended result with the code use either

If level=2 or level=3 then ...

or

if level in (2,3) then ...

🔒 This topic is solved and locked.