Solved
Contributor
Posts: 33

# how it evaluates ?

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;

when i supply level=4 why its taking expertise = "Medium" instead of "High" ?

it gives proper output when i define if condition like " level=2 or level=3 " why so ?

curious to know how sas is processing level=2 or 3 ! Thanks !

Accepted Solutions
Solution
‎07-01-2016 02:08 AM
Super User
Posts: 6,754

## Re: how it evaluates ?

3 is always true.  It has nothing to do with LEVEL, as if you had coded:

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

In SAS, 0 and missing values are false, and all other numbers are true.

This syntax would work:

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

All Replies
Solution
‎07-01-2016 02:08 AM
Super User
Posts: 6,754

## Re: how it evaluates ?

3 is always true.  It has nothing to do with LEVEL, as if you had coded:

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

In SAS, 0 and missing values are false, and all other numbers are true.

This syntax would work:

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

Posts: 5,523

## Re: how it evaluates ?

SAS is not natural language, it makes fewer assumptions;

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

should be coded as:

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

PG
🔒 This topic is solved and locked.