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

Hi all I'm new to SAS and I'm just wondering why I am getting the error below:

 

ERROR: Result of WHEN clause 3 is not the same data type as the preceding results

 

Here is my code

 

case

WHEN Year = 1617 and state in ('NSW') and Surgical_Specialty = '12' then Surgical_Specialty = '11'

WHEN Year = 1617 and t1.state in ('NT') and Surgical_Specialty in ('01','1') then Surgical_Specialty = '11'

ELSE Surgical_Specialty end as Surgical_Specialty,

 

The Year column is in Numeric

The Surgical_Specialty and STATE is in Character

 

Not sure why I cannot use year and STATE and surgical specialty in one when statement

Thankyou

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Use the correct syntax.

 

Your 2 first when clauses return a Boolean (the result of the test Surgical_Specialty = '11')

 

CASE

WHEN Year = 1617 and state in ('NSW') and Surgical_Specialty = '12'        then '11'

WHEN Year = 1617 and state in ('NT ') and Surgical_Specialty in ('01','1') then '11'

ELSE Surgical_Specialty END as Surgical_Specialty

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Use the correct syntax.

 

Your 2 first when clauses return a Boolean (the result of the test Surgical_Specialty = '11')

 

CASE

WHEN Year = 1617 and state in ('NSW') and Surgical_Specialty = '12'        then '11'

WHEN Year = 1617 and state in ('NT ') and Surgical_Specialty in ('01','1') then '11'

ELSE Surgical_Specialty END as Surgical_Specialty

kenjichan1212
Calcite | Level 5

Thank you so mcuh!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 509 views
  • 0 likes
  • 2 in conversation