title: Hash table where statement
body: <p>I'm trying to use the hash object as something like an sql query.</p>
  <p>What I wanted to know is the equivalent of a conditional if statement for SAS hash objects.</p>
  <p>I want a conditional statement on my second hash object that filters based on effective_date.</p>
  <p>Something like</p>
  <pre><code>If effective_date&lt;&quot;27.05.1966&quot;'d then output.
  </code></pre>
  <p>rc=h.find() returns a 0/1 depending if found or not found but how do I add if statements or where statements to the hash objects?</p>
  <p>I was thinking something like</p>
  <pre><code>if rc=0 and effective_date&lt;&quot;27.05.1966&quot;'d then do;
  set want;
  hoh.add();
  output;
  end;
  </code></pre>
  <p>But I don't think the hash table would know that effective_date is being referenced this way.</p>
  <p>Original proc sql statement I'm trying to translate:</p>
  <pre><code>
  proc sql;
      create table tb2 as
          select distinct
              a.effective_date,
              a.S_FACILITY_CUSTOMER_ID as customer_id,
              a.s_facility_id as facility_id,
              a.s_facility_type as facility_type,
              a.CUSTOMER_ASSET_CLASS_ID,
              a.FACILITY_START_DATE,
              a.FACILITY_end_DATE,
              sum
              (
          case 
              when midas_type_id in (&quot;KC&quot;, &quot;KR&quot;, &quot;KO&quot;,&quot;KF&quot;) then sum(a.loan_prinicpal_local,a.loan_interest_unpaid_local)
              else 0 
          end
                  )
              as arrear_amount,
  
  sum(a.LOAN_PRINICPAL_LOCAL) as amount_local
              from tbexport.tb_export_full_all a
                  where a.effective_date between &quot;&amp;repdate_from&quot;dt and &quot;&amp;repdate_to&quot;dt
  
                      AND BUSINESS_SEGMENT NOT IN (&quot;MCR&quot;, &quot;SE&quot;, &quot;COR&quot;)
                  group by s_facility_id, effective_date;
  quit;
  
  </code></pre>
  <p>This is what I come up with:</p>
  <pre><code>data _NULL_;
  
  if 0 then set tbexport.tb_export_full_all;
  
     dcl hash HoH(ordered : 'D');                                                    
     HoH.definekey('s_facility_id','effective_date');
     HoH.definedata('effective_date', 'S_FACILITY_CUSTOMER_ID', 's_facility_type','s_facility_id','CUSTOMER_ASSET_CLASS_ID',
  'FACILITY_START_DATE','FACILITY_end_DATE','midas_type_id','BUSINESS_SEGMENT','loan_prinicpal_local','loan_interest_unpaid_local');
     HoH.definedone();
     dcl hiter HoHiter('HoH');
  
    do until (lr);
        set tbexport.tb_export_full_all end=lr;
          where '&amp;repdate_from.'dt&lt;=effective_date&lt;='&amp;repdate_to.'dt;
          if HoH.find() ne 0 then do;  
   
           dcl hash h(multidata : 'Y', ordered : 'D');
           h.definekey('effective_date','s_facility_id');
           h.definedata('effective_date', 'S_FACILITY_CUSTOMER_ID', 's_facility_type','s_facility_id','CUSTOMER_ASSET_CLASS_ID',
  'FACILITY_START_DATE','FACILITY_end_DATE','midas_type_id','BUSINESS_SEGMENT','loan_prinicpal_local','loan_interest_unpaid_local');
           h.definedone();
           dcl hiter hi('h');
           HoH.add();
  
          end;    
        h.add();
     end;
  
     do until(HoHiter.next() = 1);  
          set tbexport.tb_export_full_all; 
          if hoh.find()=0 and midas_type_id in (&quot;KC&quot; , &quot;KR&quot; , &quot;KO&quot; , &quot;KF&quot;) then do;    
          arrear_amount= sum(loan_prinicpal_local,loan_interest_unpaid_local);
          end;
        hoh.output(dataset:'tb2',ordered:'A');
     end;
  
  run;
  
  </code></pre>
  <p>But it gives me this error:</p>
  <p>ERROR:  An exception has been encountered.
  Please contact technical support and provide them with the following traceback information:</p>
  <p>The SAS task name is [DATASTEP]
  Segmentation Violation</p>