<?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 Can we use data steps for many to many merge. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-data-steps-for-many-to-many-merge/m-p/265726#M52291</link>
    <description>&lt;P&gt;Can we use data steps for many to many merge.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2016 18:08:43 GMT</pubDate>
    <dc:creator>Ramanuj_Khatri</dc:creator>
    <dc:date>2016-04-22T18:08:43Z</dc:date>
    <item>
      <title>Can we use data steps for many to many merge.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-data-steps-for-many-to-many-merge/m-p/265726#M52291</link>
      <description>&lt;P&gt;Can we use data steps for many to many merge.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 18:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-data-steps-for-many-to-many-merge/m-p/265726#M52291</guid>
      <dc:creator>Ramanuj_Khatri</dc:creator>
      <dc:date>2016-04-22T18:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use data steps for many to many merge.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-data-steps-for-many-to-many-merge/m-p/265729#M52293</link>
      <description>&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sastraining/2015/05/27/life-saver-tip-for-comparing-proc-sql-join-with-sas-data-step-merge/" target="_blank"&gt;http://blogs.sas.com/content/sastraining/2015/05/27/life-saver-tip-for-comparing-proc-sql-join-with-sas-data-step-merge/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/752.html" target="_blank"&gt;http://support.sas.com/kb/24/752.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In short, no. The links above are a good resource for merges.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 18:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-data-steps-for-many-to-many-merge/m-p/265729#M52293</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-22T18:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Can we use data steps for many to many merge.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-we-use-data-steps-for-many-to-many-merge/m-p/265742#M52299</link>
      <description>&lt;P&gt;My guesss is &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;correctly interpretted your questions to be "Can I&amp;nbsp;use the MERGE statement to get a cartesian product from a&amp;nbsp;many to many&amp;nbsp;merge."&amp;nbsp; And for that,&amp;nbsp;the&amp;nbsp;answer is no.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately,&amp;nbsp;the merge statement will do a many-to-many merge,&amp;nbsp;but the results are NOT a&amp;nbsp;cartesian product.&amp;nbsp; In fact, I've never&amp;nbsp;seen&amp;nbsp;an example&amp;nbsp;where somebody actually&amp;nbsp;wanted the result of a many-to-many merge.&amp;nbsp;&amp;nbsp;But it's good to know that merge will not error in this setting, and that the note about more than one dataset with repeats of BY values&amp;nbsp;should be treated as an error.&amp;nbsp; (Unfortunately I don't&amp;nbsp;know a system option to make it an error).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;524  data a;
525    do id=1,1,2;
526      a=cats('a',id);
527      output;
528    end;
529  run;

NOTE: The data set WORK.A has 3 observations and 2 variables.

530
531  data b;
532    do id=1,1,1,2;
533      b=cats('b',id);
534      output;
535    end;
536  run;

NOTE: The data set WORK.B has 4 observations and 2 variables.

537
538  data c;
539    merge a b;
540    by id;
541    put (id a b)(=);
542  run;

id=1 a=a1 b=b1
id=1 a=a1 b=b1
id=1 a=a1 b=b1
id=2 a=a2 b=b2
NOTE: MERGE statement has more than one data set with repeats of BY values.
NOTE: There were 3 observations read from the data set WORK.A.
NOTE: There were 4 observations read from the data set WORK.B.
NOTE: The data set WORK.C has 4 observations and 3 variables.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a side note, there are&amp;nbsp;ways to use the&amp;nbsp;DATA step to create a cartesian product, just not with the MERGE statement.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 18:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-we-use-data-steps-for-many-to-many-merge/m-p/265742#M52299</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2016-04-22T18:58:02Z</dc:date>
    </item>
  </channel>
</rss>

