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
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
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
Thank you so mcuh!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.