BookmarkSubscribeRSS Feed
15GreyGoose
Calcite | Level 5

Hi!

 

I'm trying to re-work this Case When statement from SQL for use in SAS 9.4.

 

SQL / Example:  Sum(Case When IsNull(mkt_name,'') not in ('TBC', 'Web') then 1 else 0 end) as Cnt_Received_Branch

 

Here is what I think it should read:

 

SAS / Solution:  Sum(Case When mkt_name Is Null and NOT In ('TBC','Web') then 1 else 0 end) as Cnt_Received

 

However it is erroring out.  Any suggestions would be much appreciated.  I simply need the SAS equivalent  for this: 

SQL / Example:  Sum(Case When IsNull(mkt_name,'') not in ('TBC', 'Web') then 1 else 0 end) as Cnt_Received_Branch

 

 

 

Thank you SAS community,

Andrew

3 REPLIES 3
PaigeMiller
Diamond | Level 26

When mkt_name is null, then it also is not in ('TBC','Web')

 

So your query is not doing something reasonable, and probably needs to be modified.

 

Nevertheless, the SAS syntax is

 

Case When mkt_name Is Null and mkt_name NOT In ('TBC','Web')
--
Paige Miller
Reeza
Super User
ISNULL() Is more like COALESCE() but not sure exactly how that's working here, but SQL dbs do differentiate between null and missing, whereas SAS does not, so you may want to clarify the logic around that function.
Astounding
PROC Star

If this gives you the correct answer, it would certainly be easier to understand:

 

Sum(Case When mkt_name in ('TBC', 'Web') then 0 else 1 end) as Cnt_Received_Branch

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 784 views
  • 1 like
  • 4 in conversation