<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SQL JOINS TO HASH OBJECT WITH MULTIPLE CONDITIONS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617153#M180789</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table temp as
    select A.CNCPT_NM
         , A.TRRTRY_SHRT_NM
         , A.LMG_MEM_CARD_NUMBER
         , case when missing(B.REVENUE) then 'CHURN' end as FLG
    from PREV_CUST_LST A
      left join CURR_CUST_LST B on A.CNCPT_NM=B.CNCPT_NM and A.TRRTRY_SHRT_NM=B.TRRTRY_SHRT_NM and A.LMG_MEM_CARD_NUMBER=B.LMG_MEM_CARD_NUMBER
    ;

  create table CHURN_CUST as
    select CNCPT_NM
         , TRRTRY_SHRT_NM
         , count(case when FLG='CHURN' then LMG_MEM_CARD_NUMBER end) as CHURN_CUST
    from temp
    group by 1,2
    ;
  quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the basic idea of how hash coding works but struggling to resolve this with the case when missing part.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jan 2020 08:52:07 GMT</pubDate>
    <dc:creator>Bharat_P</dc:creator>
    <dc:date>2020-01-14T08:52:07Z</dc:date>
    <item>
      <title>SQL JOINS TO HASH OBJECT WITH MULTIPLE CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617153#M180789</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table temp as
    select A.CNCPT_NM
         , A.TRRTRY_SHRT_NM
         , A.LMG_MEM_CARD_NUMBER
         , case when missing(B.REVENUE) then 'CHURN' end as FLG
    from PREV_CUST_LST A
      left join CURR_CUST_LST B on A.CNCPT_NM=B.CNCPT_NM and A.TRRTRY_SHRT_NM=B.TRRTRY_SHRT_NM and A.LMG_MEM_CARD_NUMBER=B.LMG_MEM_CARD_NUMBER
    ;

  create table CHURN_CUST as
    select CNCPT_NM
         , TRRTRY_SHRT_NM
         , count(case when FLG='CHURN' then LMG_MEM_CARD_NUMBER end) as CHURN_CUST
    from temp
    group by 1,2
    ;
  quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the basic idea of how hash coding works but struggling to resolve this with the case when missing part.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 08:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617153#M180789</guid>
      <dc:creator>Bharat_P</dc:creator>
      <dc:date>2020-01-14T08:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: SQL JOINS TO HASH OBJECT WITH MULTIPLE CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617154#M180790</link>
      <description>&lt;P&gt;This should look like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set prev_cust_lst;
if _n_ = 1
then do;
  declare hash curr (dataset:"curr_cust_lst (keep=cncpt_nm trrtry_shrt_nm lmg_mem_card_number)");
  curr.definekey('cncpt_nm','trrtry_shrt_nm','lmg_mem_card_number');
  curr.definedone();
end;
if curr.check() ne 0 then flg = 'CHURN';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For tested code, supply example data in usable form (data step with datalines).&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 09:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617154#M180790</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-14T09:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: SQL JOINS TO HASH OBJECT WITH MULTIPLE CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617155#M180791</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;You should try this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table temp as
    select A.CNCPT_NM
         , A.TRRTRY_SHRT_NM
         , A.LMG_MEM_CARD_NUMBER
         , case when missing(B.REVENUE) then 'CHURN' end as FLG
    from PREV_CUST_LST A
      left join CURR_CUST_LST B on A.CNCPT_NM=B.CNCPT_NM and A.TRRTRY_SHRT_NM=B.TRRTRY_SHRT_NM and A.LMG_MEM_CARD_NUMBER=B.LMG_MEM_CARD_NUMBER
    ;

  create table CHURN_CUST as
    select CNCPT_NM
         , TRRTRY_SHRT_NM
         , sum(ifn(FLG='CHURN',1,0)) as CHURN_CUST
    from temp
    group by 1,2
    ;
  quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JD&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 09:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617155#M180791</guid>
      <dc:creator>JeanDo</dc:creator>
      <dc:date>2020-01-14T09:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: SQL JOINS TO HASH OBJECT WITH MULTIPLE CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617158#M180792</link>
      <description>&lt;P&gt;And the whole operation should look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=prev_cust_lst;
by cncpt_nm trrtry_shrt_nm;
run;

data churn_cust (keep=cncpt_nm trrtry_shrt_nm churn_cust);
set prev_cust_lst;
by cncpt_nm trrtry_shrt_nm;
if _n_ = 1
then do;
  declare hash curr (dataset:"curr_cust_lst (keep=cncpt_nm trrtry_shrt_nm lmg_mem_card_number)");
  curr.definekey('cncpt_nm','trrtry_shrt_nm','lmg_mem_card_number');
  curr.definedone();
end;
if first.trrtry_shrt_nm then churn_cust = 0;
if curr.check() ne 0 then churn_cust + 1;
if last.trrtry_shrt_nm;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 09:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617158#M180792</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-14T09:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: SQL JOINS TO HASH OBJECT WITH MULTIPLE CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617159#M180793</link>
      <description>&lt;P&gt;You guys are unbelievably helpful. You guys make our worklife so easy.. thank you from the bottom of my heart&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 09:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-JOINS-TO-HASH-OBJECT-WITH-MULTIPLE-CONDITIONS/m-p/617159#M180793</guid>
      <dc:creator>Bharat_P</dc:creator>
      <dc:date>2020-01-14T09:56:04Z</dc:date>
    </item>
  </channel>
</rss>

