<?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 all from both tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Join-all-from-both-tables/m-p/689550#M209637</link>
    <description>Hi:&lt;BR /&gt;  Take a look at the sample code here: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Merging-Tables/td-p/580772" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Merging-Tables/td-p/580772&lt;/A&gt; on the 8/17/2019 posting. It shows 5 of the possible combinations from 2 datasets being merged. Your example seems very similar.&lt;BR /&gt;Cynthia</description>
    <pubDate>Wed, 07 Oct 2020 13:43:11 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2020-10-07T13:43:11Z</dc:date>
    <item>
      <title>Join all from both tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-all-from-both-tables/m-p/689527#M209634</link>
      <description>&lt;P&gt;Hi I need some help !&lt;/P&gt;&lt;P&gt;basically i need table 1 and table 2 become table 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 1&lt;/P&gt;&lt;P&gt;key&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;desc1&lt;/P&gt;&lt;P&gt;012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp;check&lt;/P&gt;&lt;P&gt;013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp;nothing&lt;/P&gt;&lt;P&gt;013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp;left&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 2&lt;/P&gt;&lt;P&gt;key&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; desc2&lt;/P&gt;&lt;P&gt;012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; up&lt;/P&gt;&lt;P&gt;012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; down&lt;/P&gt;&lt;P&gt;013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; right&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 3&lt;/P&gt;&lt;P&gt;key&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; desc1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;desc2&lt;/P&gt;&lt;P&gt;012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;1/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;check&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;up&lt;/P&gt;&lt;P&gt;012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;check&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;down&lt;/P&gt;&lt;P&gt;013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;nothing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;right&lt;/P&gt;&lt;P&gt;013&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9/1/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;left&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; right&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 12:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-all-from-both-tables/m-p/689527#M209634</guid>
      <dc:creator>someone_new</dc:creator>
      <dc:date>2020-10-07T12:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Join all from both tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-all-from-both-tables/m-p/689550#M209637</link>
      <description>Hi:&lt;BR /&gt;  Take a look at the sample code here: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Merging-Tables/td-p/580772" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Merging-Tables/td-p/580772&lt;/A&gt; on the 8/17/2019 posting. It shows 5 of the possible combinations from 2 datasets being merged. Your example seems very similar.&lt;BR /&gt;Cynthia</description>
      <pubDate>Wed, 07 Oct 2020 13:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-all-from-both-tables/m-p/689550#M209637</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-10-07T13:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Join all from both tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-all-from-both-tables/m-p/689553#M209638</link>
      <description>&lt;P&gt;For the data you posted, a simple MERGE does it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
input key $ date :ddmmyy10. desc1 $;
format date yymmdd10.;
datalines;
012          1/1/2019     check
013          1/1/2019     nothing
013          9/1/2019     left
;
 
data table2;
input key $ date :ddmmyy10. desc2 $;
format date yymmdd10.;
datalines;
012         1/1/2019      up
012         9/1/2019      down
013         1/1/2019      right
;

data table3;
merge
  table1
  table2
;
by key;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this is only true until you run into a situation where there is more than one observation for a given key in both datasets; in this case, you will need a SQL full join, and some logic to deal with the dates, like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table table3 as
  select
    coalesce(t1.key,t2.key) as key,
    max(t1.date,t2.date) as date format=yymmdd10.,
    t1.desc1,
    t2.desc2
  from
    table1 t1
  full join
    table2 t2
  on t1.key = t2.key
  order by calculated key, calculated date
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2020 13:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-all-from-both-tables/m-p/689553#M209638</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-07T13:49:34Z</dc:date>
    </item>
  </channel>
</rss>

