<?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: Dataset Merge with incorrect results in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788701#M252230</link>
    <description>SAS data step cannot do a many to many merge, use the SQL solution instead. &lt;BR /&gt;&lt;BR /&gt;Note: The MERGE statement does not produce a Cartesian product on a many-to-many match-merge. Instead, it performs a one-to-one merge while there are observations in the BY group in at least one data set. When all observations in the BY group have been read from one data set and there are still more observations in another data set, SAS performs a one-to-many merge until all BY group observations have been read.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm#p1rfsa0978il4yn1q7s3rknmzfyr" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm#p1rfsa0978il4yn1q7s3rknmzfyr&lt;/A&gt;</description>
    <pubDate>Thu, 06 Jan 2022 17:29:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-01-06T17:29:58Z</dc:date>
    <item>
      <title>Dataset Merge with incorrect results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788696#M252225</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;I have two datasets to merge but the results are not what I need.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HAVE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset1:&lt;/P&gt;&lt;P&gt;gic_id&amp;nbsp; &amp;nbsp;gic_acct&amp;nbsp; gic_certno&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;111&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;112&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset2 (contains customer name, address etc and gic_acct):&lt;/P&gt;&lt;P&gt;gic_acct&amp;nbsp; &amp;nbsp; &amp;nbsp;cust_name&amp;nbsp; &amp;nbsp; cust_number&lt;/P&gt;&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8888&lt;/P&gt;&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9999&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want (after merge):&lt;/P&gt;&lt;P&gt;since both customers share the same gic accounts:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gic_id&amp;nbsp; &amp;nbsp;gic_acct&amp;nbsp; gic_certno&amp;nbsp; &amp;nbsp;cust_name&amp;nbsp; &amp;nbsp; cust_number&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8888&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9999&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;112&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8888&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;112&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9999&lt;/P&gt;&lt;P&gt;=====================================================&lt;/P&gt;&lt;P&gt;my code:&lt;/P&gt;&lt;P&gt;proc sort data=dataset1&amp;nbsp; &amp;nbsp;out=d1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;by gic_acct;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=dataset2&amp;nbsp; &amp;nbsp;out=d2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; by gic_acct;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data merg1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; merge&amp;nbsp; &amp;nbsp;d1&amp;nbsp; (in=a)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; d2 (in=b);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; by gic_acct;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if a and b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Resulting output:&lt;/P&gt;&lt;P&gt;gic_id&amp;nbsp; &amp;nbsp;gic_acct&amp;nbsp; gic_certno&amp;nbsp; &amp;nbsp;cust_name&amp;nbsp; &amp;nbsp; cust_number&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8888&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;112&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Bob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9999&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greatly appreciate your assistance!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 17:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788696#M252225</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2022-01-06T17:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset Merge with incorrect results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788700#M252229</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355588"&gt;@sasasauraus&lt;/a&gt;&amp;nbsp; Please think of SQL when you have &lt;STRONG&gt;&lt;EM&gt;many to many&lt;/EM&gt;&lt;/STRONG&gt; relationship and datastep for &lt;STRONG&gt;&lt;EM&gt;one to one or one to many&lt;/EM&gt;&lt;/STRONG&gt; relationships-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data set1;
input gic_id   gic_acct  gic_certno;
cards;
7           1234       111
8            1234       112
;

data set2;
input gic_acct     cust_name  $  cust_number;
cards;
1234           Jane              8888
1234           Bob               9999
;

proc sql;
  create table want as
  select a.*, cust_name, cust_number
  from set1 a inner join set2 b
  on a.gic_acct=b.gic_acct
  order by gic_id,gic_acct;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 17:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788700#M252229</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2022-01-06T17:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset Merge with incorrect results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788701#M252230</link>
      <description>SAS data step cannot do a many to many merge, use the SQL solution instead. &lt;BR /&gt;&lt;BR /&gt;Note: The MERGE statement does not produce a Cartesian product on a many-to-many match-merge. Instead, it performs a one-to-one merge while there are observations in the BY group in at least one data set. When all observations in the BY group have been read from one data set and there are still more observations in another data set, SAS performs a one-to-many merge until all BY group observations have been read.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm#p1rfsa0978il4yn1q7s3rknmzfyr" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lestmtsref/n1i8w2bwu1fn5kn1gpxj18xttbb0.htm#p1rfsa0978il4yn1q7s3rknmzfyr&lt;/A&gt;</description>
      <pubDate>Thu, 06 Jan 2022 17:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788701#M252230</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-06T17:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset Merge with incorrect results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788730#M252256</link>
      <description>&lt;P&gt;Thank you very much for the solution and speedy reply.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 20:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788730#M252256</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2022-01-06T20:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Dataset Merge with incorrect results</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788731#M252257</link>
      <description>&lt;P&gt;Thank you Reeza for the details.&amp;nbsp; The SAS Community board rocks!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 20:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dataset-Merge-with-incorrect-results/m-p/788731#M252257</guid>
      <dc:creator>sasasauraus</dc:creator>
      <dc:date>2022-01-06T20:09:42Z</dc:date>
    </item>
  </channel>
</rss>

