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

I 'm trying to do this CASE statement

Case when LN_REGULAT.ACTION_TAKEN in ( 3, 7) then LN_REGULAT.ACTION_DATE else Null end 'DENIED_DATE' ,

70 Case when LN_REGULAT.ACTION_TAKEN in( 2, 4,5,8) then LN_REGULAT.ACTION_DATE else Null end 'WITHDRAWN_DATE'

, but I got an error message saying that  "ERROR: The following columns were not found in the contributing tables: Null "

 

I then changed Null to '.', I got this error : "ERROR: Result of WHEN clause 2 is not the same data type as the preceding results."

If I was to connect to table  LN_REGULAT directly from the data source, this case statement works.

 

but if I create the table as (select * form connection......), and then run this case statement, it doesn't work.

Could you please help?

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Ah, then the quotes should be a period instead.

Case when LN_REGULAT.ACTION_TAKEN in ( 3, 7) then LN_REGULAT.ACTION_DATE else . end as DENIED_DATE

View solution in original post

5 REPLIES 5
Reeza
Super User
SAS doesn't have a concept of NULL, instead replace it with quotation marks with nothing in between them, ie "".
You likely don't want quotes around your new name either.

Case when LN_REGULAT.ACTION_TAKEN in ( 3, 7) then LN_REGULAT.ACTION_DATE else "" end as DENIED_DATE
MelissaN
Obsidian | Level 7

Thanks for you response.

I got this error instead

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

LN_REGULAT.ACTION_DATE is a datetime value

Reeza
Super User
Ah, then the quotes should be a period instead.

Case when LN_REGULAT.ACTION_TAKEN in ( 3, 7) then LN_REGULAT.ACTION_DATE else . end as DENIED_DATE
Tom
Super User Tom
Super User

For your examples you can just eliminate the ELSE clause and the resulting value will be missing without you having to know whether you want numeric or character missing.  You might get a note about the missing ELSE but it should work.

,case when LN_REGULAT.ACTION_TAKEN in (3,7) then LN_REGULAT.ACTION_DATE 
 end 'DENIED_DATE' 
,case when LN_REGULAT.ACTION_TAKEN in (2,4,5,8) then LN_REGULAT.ACTION_DATE 
 end 'WITHDRAWN_DATE'
MelissaN
Obsidian | Level 7

This also works as well. Thanks for your help.

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