Hi, Hopefully an easy question to solve, but I'm back to using Base SAS after 8 years of using SAS Enterprise Guide and I'm getting a mental block!! Below is my proc sql code proc sql; create table mktg_count as select PROD_DETAIL, count(distinct DM_CUST_KEY) as Total_Customers, sum( case when valid_email = 'Y' and SUPRS_EMAIL_FLAG = 'N' and OPT_OUT_FLAG = 'N' then 1 else 0 end) as Emailable, sum( case when SUPRS_MAIL_FLAG = 'N' and OPT_OUT_FLAG = 'N' then 1 else 0 end) as Mailable from cust_emails where PROD_DETAIL not in ('Home','Motor') group by PROD_DETAIL; quit; What I'm trying to do is create the Emailable and Mailable columns for the distinct values of Total Customers, but my sum function is bringing back the sum for the whole of my table instead. Can anybody please help me with this so that the sum function is only on distinct customers. I've tried putting the calculated columns in the group by statement, but that doesn't seem to work. Thanks, Dan
... View more