<?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 Re: Join SAS tables with condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474385#M121887</link>
    <description>&lt;P&gt;Look if this suits you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data contracts;
input contract_id $ premium start_date :yymmdd10. end_date :yymmdd10.;
format start_date end_date yymmddd10.;
cards;
C1 100 2016-01-01 2016-12-31
C1 110 2017-01-01 2017-12-31
;
run;

data claims;
input contract_id $ amount occur_date :yymmdd10.;
format occur_date yymmddd10.;
cards;
C1 50 2016-03-05
C1 20 2016-09-01
C1 30 2017-06-29
;
run;

proc sql;
create table want as
select
  a.contract_id,
  a.start_date,
  a.end_date,
  sum(b.amount) as amount
from
  contracts a
  left join
  claims b
  on (a.contract_id=b.contract_id and a.start_date &amp;lt;= b.occur_date &amp;lt;= a.end_date)
group by
  a.contract_id,a.start_date,a.end_date
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Jun 2018 08:47:51 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-06-29T08:47:51Z</dc:date>
    <item>
      <title>Join SAS tables with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474381#M121884</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;i need to join two sas tables with condition,&lt;/P&gt;&lt;P&gt;The first tables contains a list of contract with two dates : start date and expiration date, and also the premium.&lt;/P&gt;&lt;P&gt;the second table contains claims with occurence date, amounts and contract.&lt;/P&gt;&lt;P&gt;i have to join those tables by contract, the occurence date have to be between start date and expiration date.&lt;/P&gt;&lt;P&gt;A contract may have many claims, i need to sum the amounts of claims and affected to the contract .&lt;/P&gt;&lt;P&gt;My main problem is how to join those tables and to avoid duplicates (premium)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i Tried to use the SQL procedure, right join/full join. but it doesn't work,&lt;/P&gt;&lt;P&gt;also&amp;nbsp; i tried the merge procedure,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a Lot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 08:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474381#M121884</guid>
      <dc:creator>Mirou</dc:creator>
      <dc:date>2018-06-29T08:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Join SAS tables with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474384#M121886</link>
      <description>&lt;P&gt;"i Tried to use the SQL procedure, right join/full join. but it doesn't work, also&amp;nbsp; i tried the merge procedure, "&amp;nbsp; - this does not tell us anything.&amp;nbsp; Posting test data in the form of a datastep, what the output should look like, and what you have done will.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would say SQL is likely the simplest option:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
  select  a.contract,
          a.start_date,
          a.end_date,
          sum(b.amount) as amount
  from    first_table a
  left join second_table b
  on      a.contract=b.contract
  and     a.start_date &amp;lt;= b.occurence_date &amp;lt;= a.end_date
  group by a.contract,
           a.start_date,
           b.end_date;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 08:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474384#M121886</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-29T08:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Join SAS tables with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474385#M121887</link>
      <description>&lt;P&gt;Look if this suits you:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data contracts;
input contract_id $ premium start_date :yymmdd10. end_date :yymmdd10.;
format start_date end_date yymmddd10.;
cards;
C1 100 2016-01-01 2016-12-31
C1 110 2017-01-01 2017-12-31
;
run;

data claims;
input contract_id $ amount occur_date :yymmdd10.;
format occur_date yymmddd10.;
cards;
C1 50 2016-03-05
C1 20 2016-09-01
C1 30 2017-06-29
;
run;

proc sql;
create table want as
select
  a.contract_id,
  a.start_date,
  a.end_date,
  sum(b.amount) as amount
from
  contracts a
  left join
  claims b
  on (a.contract_id=b.contract_id and a.start_date &amp;lt;= b.occur_date &amp;lt;= a.end_date)
group by
  a.contract_id,a.start_date,a.end_date
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jun 2018 08:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474385#M121887</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-29T08:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: Join SAS tables with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474386#M121888</link>
      <description>&lt;P&gt;thanks you RW9, i will try it&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 08:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474386#M121888</guid>
      <dc:creator>Mirou</dc:creator>
      <dc:date>2018-06-29T08:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Join SAS tables with condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474387#M121889</link>
      <description>&lt;P&gt;thanks !&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 08:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-SAS-tables-with-condition/m-p/474387#M121889</guid>
      <dc:creator>Mirou</dc:creator>
      <dc:date>2018-06-29T08:58:07Z</dc:date>
    </item>
  </channel>
</rss>

