BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Attyslogin
Obsidian | Level 7

 

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 !   

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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

PGStats
Opal | Level 21

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

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
  • 2 replies
  • 873 views
  • 3 likes
  • 3 in conversation