<?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: many-to-many merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834506#M329922</link>
    <description>&lt;P&gt;Here's an approach you can take:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   in1=0;
   in2=0;
   merge a (in=in1) b (in=in2);
   by id;
   if first.id=0 and in1 and in2 then do;
      /* bad situation encountered ... end it how you wish but here is one way */
      put id=;
      stop;   /* or abort is also possible */
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Sep 2022 15:08:10 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2022-09-21T15:08:10Z</dc:date>
    <item>
      <title>many-to-many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834474#M329911</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I run a merge of many-to-one or one-to-one.&lt;/P&gt;
&lt;P&gt;How can I tell SAS to stop running the code and get error of the Merge is Many-To-Many?&lt;/P&gt;
&lt;P&gt;note:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The merge should be one-to-one or one-to-many but if the raw data is faulty then IT might happen that it will be many-to-many and in such case i want to tell sas stop running the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 13:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834474#M329911</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-09-21T13:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834486#M329914</link>
      <description>&lt;P&gt;Before you do the merge, run a check step on the dataset which is supposed to have only unique entries:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let non_unique = 0;
data _null_;
set have1;
by key;
if first.key ne last.key
then do;
  call symputx('non_unique',1);
  stop;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can now use the macro variable to control further action.&lt;/P&gt;
&lt;P&gt;If this shall be part of a batch job, you can use ABORT ABEND (in place of CALL SYMPUTX) with a predefined exit code to alert the scheduler.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 14:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834486#M329914</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-21T14:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834496#M329918</link>
      <description>&lt;P&gt;You can actually reset the IN= variables and make it so you can detect many to many merge situations in a data step merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if it is not the first observation for a BY group and more than one of the IN= variables is true then you have an ID that has more than one observation contributed from more than one dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  input id @@;
  var1=1;
cards;
1 2 3 3 3 4 
;
data two;
  input id @@;
  var2=1;
cards;
1 2 2 3 3 4 
;

data want ;
  merge one(in=in1) two(in=in2);
  by id;
  if first.id then row=0;
  row+1;
  if sum(in1,in2)&amp;gt;1 and not first.id then do;
      put 'MANY TO MANY MERGE ' id= row= in1= in2=;
  end;
  call missing(in1,in2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;PRE&gt;770   data want ;
771     merge one(in=in1) two(in=in2);
772     by id;
773     if first.id then row=0;
774     row+1;
775     if sum(in1,in2)&amp;gt;1 and not first.id then do;
776         put 'MANY TO MANY MERGE ' id= row= in1= in2=;
777     end;
778     call missing(in1,in2);
779   run;

MANY TO MANY MERGE id=3 row=2 in1=1 in2=1
NOTE: MERGE statement has more than one data set with repeats of BY values.
NOTE: The data set WORK.WANT has 7 observations and 4 variables.
&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Sep 2022 14:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834496#M329918</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-21T14:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: many-to-many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834506#M329922</link>
      <description>&lt;P&gt;Here's an approach you can take:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   in1=0;
   in2=0;
   merge a (in=in1) b (in=in2);
   by id;
   if first.id=0 and in1 and in2 then do;
      /* bad situation encountered ... end it how you wish but here is one way */
      put id=;
      stop;   /* or abort is also possible */
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Sep 2022 15:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/many-to-many-merge/m-p/834506#M329922</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-09-21T15:08:10Z</dc:date>
    </item>
  </channel>
</rss>

