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

Hi,

 

I am writing a when clause saying:

case when put(AB,1.)='1' then XY='0' else XY end as XY

 

AB is numeric and so to put it in the case statement I converted it to char but it is still saying the error "Result of when clause 2 is not the same data type as the preceding results".

XY is character.

 

How can I put the case statement here !

 

Thanks in advance:)

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@new_sas_user_4 wrote:

Hi,

 

I am writing a when clause saying:

case when put(AB,1.)='1' then XY='0' else XY end as XY

 

AB is numeric and so to put it in the case statement I converted it to char but it is still saying the error "Result of when clause 2 is not the same data type as the preceding results".

XY is character.

 

How can I put the case statement here !

 


The expression XY='0' is a Boolean expression, it evaluates as either true or false which in SAS is a numeric one or zero. So you can't have a numeric in one case (when put(AB,1.)='1' then XY='0') and a character XY in the other case.

 

Try this:

case when AB=1 then '0' else XY end as XY

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@new_sas_user_4 wrote:

Hi,

 

I am writing a when clause saying:

case when put(AB,1.)='1' then XY='0' else XY end as XY

 

AB is numeric and so to put it in the case statement I converted it to char but it is still saying the error "Result of when clause 2 is not the same data type as the preceding results".

XY is character.

 

How can I put the case statement here !

 


The expression XY='0' is a Boolean expression, it evaluates as either true or false which in SAS is a numeric one or zero. So you can't have a numeric in one case (when put(AB,1.)='1' then XY='0') and a character XY in the other case.

 

Try this:

case when AB=1 then '0' else XY end as XY

 

--
Paige Miller
new_sas_user_4
Quartz | Level 8

Thanks a lot 🙂 🙂

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 3193 views
  • 0 likes
  • 2 in conversation