Unfortunately I am not a coder…I have used CASE statements before but not in combination with "LIKE". I'm not sure if my issues have to do with CASE or something else.
I am using proc sql (SAS) to identify cases that have purchased specific products as defined by the COMPANY and by words in the PROD_LONG_NM. This will be a series of statements necessary for each COMPANY and PROD-LONG_NM combination.
Any cases that meet a definition will be flagged and can then be excluded from further consideration for the remaining statements – if they don’t meet the definition then they need to be considered by subsequent statements until they do meet one…
For example, this statement runs without (syntax) errors but logically does not find any cases until fire_smbiz_conv and then not all of them. The final six statements pick up ALL the cases without omitting what should have been picked up by the previous CASE/LIKE statements:
case when company='MUTUAL FUNDS' and (PROD_LONG_NM LIKE '401') or (PROD_LONG_NM LIKE 'SEP') or (PROD_LONG_NM LIKE 'SIMPLE')
then 1 else 0 end as mf_smbiz_conv,
case when company='BANK' and (PROD_LONG_NM LIKE 'BUSINESS')
then 1 else 0 end as bk_smbiz_conv,
case when company='AUTO' and (PROD_LONG_NM LIKE 'COMMERCIAL') or (PROD_LONG_NM LIKE 'ENOL') or (PROD_LONG_NM LIKE 'BUSINESS')
then 1 else 0 end as auto_smbiz_conv,
case when company='FIRE' and (PROD_LONG_NM LIKE 'BUSINESS') or (PROD_LONG_NM LIKE 'COMMERCIAL') or (PROD_LONG_NM LIKE 'CONTRACTORS')
or (PROD_LONG_NM LIKE 'RANCH') or (PROD_LONG_NM LIKE 'FIDELITY') or (PROD_LONG_NM LIKE 'RENTAL')
or (PROD_LONG_NM LIKE 'SURETY') or (PROD_LONG_NM LIKE 'WORKERS')
then 1 else 0 end as fire_smbiz_conv,
case when company='AUTO' then 1 else 0 end as oth_auto_conv,
case when company='FIRE' then 1 else 0 end as oth_fire_conv,
case when company='LIFE' then 1 else 0 end as oth_life_conv,
case when company='HEALTH' then 1 else 0 end as oth_health_conv,
case when company='MUTUAL FUNDS' then 1 else 0 end as oth_mf_conv,
case when company='BANK' then 1 else 0 end as oth_bank_conv