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

Hi,

 

I received this error when I tried to do a count distinct with conditions in proc sql:

 

proc sql;
create table cnt_SOR as
select
default_dt_yyyymm,
count(distinct (case when app_sys_no = '337' then obligor_no else 0 end)) as Cnt337,
count(distinct (case when app_sys_no = '339' then obligor_no else 0 end)) as Cnt339,
count(distinct (case when app_sys_no = '342' then obligor_no else 0 end)) as Cnt342,
count(distinct (case when app_sys_no = '362' then obligor_no else 0 end)) as Cnt362
from auto_LGD
where default_dt_yyyymm >= 201501 and app_sys_no in ('337', '339', '342', '362')
group by 1 order by 1;
quit;

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

 

Could someone help me on what's going on? app_sys_no is character format, and I don't see other data type conflicts here.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisBrooks
Ammonite | Level 13

The problem isn't with app_sys_no - it's because obligor is, presumably, character and 0 is of course numeric.

 

If you change your case statements to read as follows you should be OK

 

count(distinct (case when app_sys_no = '337' then obligor_no else "" end)) as Cnt337, 
count(distinct (case when app_sys_no = '339' then obligor_no else "" end)) as Cnt339, 
count(distinct (case when app_sys_no = '342' then obligor_no else "" end)) as Cnt342, 
count(distinct (case when app_sys_no = '362' then obligor_no else "" end)) as Cnt362 

View solution in original post

3 REPLIES 3
ChrisBrooks
Ammonite | Level 13

The problem isn't with app_sys_no - it's because obligor is, presumably, character and 0 is of course numeric.

 

If you change your case statements to read as follows you should be OK

 

count(distinct (case when app_sys_no = '337' then obligor_no else "" end)) as Cnt337, 
count(distinct (case when app_sys_no = '339' then obligor_no else "" end)) as Cnt339, 
count(distinct (case when app_sys_no = '342' then obligor_no else "" end)) as Cnt342, 
count(distinct (case when app_sys_no = '362' then obligor_no else "" end)) as Cnt362 
Bankshot
Obsidian | Level 7

Thanks Chris!  This was very helpful

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 10189 views
  • 4 likes
  • 3 in conversation