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

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
Obsidian | Level 7

Thanks a lot 🙂 🙂

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!

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