<?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 DATA STEP merge on composite key? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-merge-on-composite-key/m-p/451173#M113703</link>
    <description>&lt;P&gt;How do I merge datasets on more than one key?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something equivalent to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  SELECT *
  FROM table_a JOIN table_b ON (table_a.col1 = table_b.col1 AND table_a.col2 = table_b.col2);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Apr 2018 16:00:00 GMT</pubDate>
    <dc:creator>tomcmacdonald</dc:creator>
    <dc:date>2018-04-04T16:00:00Z</dc:date>
    <item>
      <title>DATA STEP merge on composite key?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-merge-on-composite-key/m-p/451173#M113703</link>
      <description>&lt;P&gt;How do I merge datasets on more than one key?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something equivalent to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  SELECT *
  FROM table_a JOIN table_b ON (table_a.col1 = table_b.col1 AND table_a.col2 = table_b.col2);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Apr 2018 16:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-merge-on-composite-key/m-p/451173#M113703</guid>
      <dc:creator>tomcmacdonald</dc:creator>
      <dc:date>2018-04-04T16:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP merge on composite key?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-merge-on-composite-key/m-p/451186#M113706</link>
      <description>&lt;P&gt;The equivalent would be along these lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data sets must be in order first.&amp;nbsp; If not, sort them:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=table_a;&lt;/P&gt;
&lt;P&gt;by col1 col2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=table_b;&lt;/P&gt;
&lt;P&gt;by col1 col2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then MERGE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge table_a (in=found_in_table_a)&lt;/P&gt;
&lt;P&gt;table_b (in=found_in_table_b);&lt;/P&gt;
&lt;P&gt;by col1 col2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also add to the DATA step, utilizing the temporary flags (in this case named FOUND_IN_TABLE_A and FOUND_IN_TABLE_B).&amp;nbsp; Those flags could subset the records to get the equivalent of left, right, or inner joins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing that is different in a DATA step vs. SQL:&amp;nbsp; the variables COL1 and COL2 should have same attributes in both incoming data sets.&amp;nbsp; Results are not guaranteed, for example, if COL1 has a different length in TABLE_A vs. in TABLE_B.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 16:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-merge-on-composite-key/m-p/451186#M113706</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-04T16:12:07Z</dc:date>
    </item>
  </channel>
</rss>

