<?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: Question on many to many merge in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Question-on-many-to-many-merge/m-p/959732#M43104</link>
    <description>&lt;P&gt;The reason a one to many merge works in the SAS data step is because variables coming from input datasets are RETAINED.&amp;nbsp; &amp;nbsp;To prevent that you just need to add your own code to clear them.&amp;nbsp; That is very easy to do using CALL MISSING().&amp;nbsp; Just make sure to write the observation BEFORE you clear the values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data c;
  merge a b;
  by ID;
  output;
  call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 20 Feb 2025 02:42:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-02-20T02:42:55Z</dc:date>
    <item>
      <title>Question on many to many merge</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-on-many-to-many-merge/m-p/959731#M43103</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input ID x;
datalines;
1 a
1 b
3 c
run;

data b;
  input ID y;
datalines;
1 a
1 b
1 c
run;

data c;
  merge a b;
  by ID;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;obs ID x y
  1  1 a a
  2  1 b b
  3  1 b c
  4  3 c&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My question is, is there a way to produce an output as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;obs ID x y
  1  1 a a
  2  1 b b
  3  1   c
  4  3 c&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 02:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-on-many-to-many-merge/m-p/959731#M43103</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2025-02-20T02:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Question on many to many merge</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-on-many-to-many-merge/m-p/959732#M43104</link>
      <description>&lt;P&gt;The reason a one to many merge works in the SAS data step is because variables coming from input datasets are RETAINED.&amp;nbsp; &amp;nbsp;To prevent that you just need to add your own code to clear them.&amp;nbsp; That is very easy to do using CALL MISSING().&amp;nbsp; Just make sure to write the observation BEFORE you clear the values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data c;
  merge a b;
  by ID;
  output;
  call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Feb 2025 02:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-on-many-to-many-merge/m-p/959732#M43104</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-20T02:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: Question on many to many merge</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Question-on-many-to-many-merge/m-p/959734#M43105</link>
      <description>&lt;P&gt;I normally prefer SQL for such cases. I feel it's "cleaner".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input ID x $;
datalines;
1 a
1 b
3 c
;
run;

data b;
  input ID y $;
datalines;
1 a
1 b
1 c
;
run;

proc sql;
/*   create table want as */
  select 
    coalesce(a.id,b.id) as id,
    a.x,
    b.y
  from a
  full join b 
  on a.id=b.id and a.x=b.y
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1740019663485.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104781i3F14CBF813CFD023/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1740019663485.png" alt="Patrick_0-1740019663485.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The relationship between your tables with the keys used is actually not many:many but 1:1 (well: 1 or zero : 1 or zero).&lt;BR /&gt;For many:many joins the result (number of rows) between a SQL join and a data step merge will differ (most of the time you're after the SQL result).&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 02:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Question-on-many-to-many-merge/m-p/959734#M43105</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2025-02-20T02:55:38Z</dc:date>
    </item>
  </channel>
</rss>

