<?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: Combine 2 Tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501002#M133518</link>
    <description>&lt;P&gt;A simple &lt;FONT face="courier new,courier"&gt;merge by&lt;/FONT&gt; should do this perfectly. Why a hash solution?&lt;/P&gt;</description>
    <pubDate>Wed, 03 Oct 2018 01:23:56 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-10-03T01:23:56Z</dc:date>
    <item>
      <title>Combine 2 Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/500996#M133513</link>
      <description>&lt;P&gt;Hey guys,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following 2 tables old and update and want to have the output like want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.old;
input (Date cusip fundid mod) ($);
datalines;
Mar2012 123  A  5$
Mar2012 124  A  5$
Apr2012 124  B  6$
;

data work.update;
input (Date cusip fundid mod) ($);
datalines;
Apr2012 124  B  7$
May2012 124  B  10$
;

data work.want;
input (Date cusip fundid mod) ($);
datalines;
Mar2012 123  A  5$
Mar2012 124  A  5$
Apr2012 124  B  7$
May2012 124  B  10$
;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;That means: Table want should have all (date-cusip)-observations from work.update and&amp;nbsp;&lt;/P&gt;&lt;P&gt;only those (date-cusip)-observations from work.old that are not in work.update.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each date-cusip-Combination can exist more than once in both tables (with different fundids) but always have the same&lt;/P&gt;&lt;P&gt;value for mod.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It can be said, that work.old is a bigger table than work.update, so it would be perfect if someone could provide me a hash solution&amp;nbsp;&lt;/P&gt;&lt;P&gt;(for better performance).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&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>Wed, 03 Oct 2018 00:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/500996#M133513</guid>
      <dc:creator>mrzlatan91</dc:creator>
      <dc:date>2018-10-03T00:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501002#M133518</link>
      <description>&lt;P&gt;A simple &lt;FONT face="courier new,courier"&gt;merge by&lt;/FONT&gt; should do this perfectly. Why a hash solution?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 01:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501002#M133518</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-10-03T01:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501003#M133519</link>
      <description>&lt;P&gt;There's probably a hash solution for this, but here's my plain vanilla solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=old;&lt;/P&gt;
&lt;P&gt;by date cusip fundid;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=update;&lt;/P&gt;
&lt;P&gt;by date cusip fundid;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge old update;&lt;/P&gt;
&lt;P&gt;by date cusip fundid;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It brings in all the data, but when there is a match uses the data from UPDATE to overwrite the data from OLD.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 01:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501003#M133519</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-03T01:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501006#M133522</link>
      <description>&lt;P&gt;Would an UPDATE statement work? You need to sort the data ahead of time but it works well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
update old update;
by date cusip fundid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/186452"&gt;@mrzlatan91&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following 2 tables old and update and want to have the output like want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.old;
input (Date cusip fundid mod) ($);
datalines;
Mar2012 123  A  5$
Mar2012 124  A  5$
Apr2012 124  B  6$
;

data work.update;
input (Date cusip fundid mod) ($);
datalines;
Apr2012 124  B  7$
May2012 124  B  10$
;

data work.want;
input (Date cusip fundid mod) ($);
datalines;
Mar2012 123  A  5$
Mar2012 124  A  5$
Apr2012 124  B  7$
May2012 124  B  10$
;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That means: Table want should have all (date-cusip)-observations from work.update and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;only those (date-cusip)-observations from work.old that are not in work.update.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each date-cusip-Combination can exist more than once in both tables (with different fundids) but always have the same&lt;/P&gt;
&lt;P&gt;value for mod.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can be said, that work.old is a bigger table than work.update, so it would be perfect if someone could provide me a hash solution&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(for better performance).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 01:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501006#M133522</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-03T01:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501011#M133525</link>
      <description>Looks a plain append/interleave to me</description>
      <pubDate>Wed, 03 Oct 2018 01:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501011#M133525</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-03T01:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501045#M133543</link>
      <description>&lt;P&gt;If your OLD dataset is large, and you do not need to keep the previous version, updating in place may be the fast way to do it:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.old;
  modify old update;
  by date cusip;
  if _iorc_ then do;
    output;
	_error_=0;
	end;
  else replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The _IORC_ is set when there is an observation in UPDATE that does not have a correspondent key in OLD.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you need to improve the performance more, index your OLD table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
  create Unique index idx on old(date,cusip);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 07:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501045#M133543</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-03T07:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501106#M133572</link>
      <description>&lt;P&gt;thanks, your solution&amp;nbsp;has the best performance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 12:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501106#M133572</guid>
      <dc:creator>mrzlatan91</dc:creator>
      <dc:date>2018-10-03T12:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Combine 2 Tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501108#M133573</link>
      <description>&lt;P&gt;yes, this worked as well. thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 12:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-2-Tables/m-p/501108#M133573</guid>
      <dc:creator>mrzlatan91</dc:creator>
      <dc:date>2018-10-03T12:30:41Z</dc:date>
    </item>
  </channel>
</rss>

