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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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