<?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: Extra data entries when I merge two tables - help with merge in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531371#M32946</link>
    <description>&lt;P&gt;Double-check your TABLE2.&amp;nbsp; Is it possible that it contains two entries for the same ANIMAL?&amp;nbsp; That would create the problem that you are describing.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jan 2019 14:29:44 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-01-30T14:29:44Z</dc:date>
    <item>
      <title>Extra data entries when I merge two tables - help with merge</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531310#M32943</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently using SAS Enterprise Guide, and wish to merge two data sets based on a common variable. I wish to do a left join I believe, as I wish to keep every data row from the left table, and match with the right table to add an extra variable onto the left table. See below for an example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Table2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Animal&amp;nbsp; Name&amp;nbsp; Age&amp;nbsp; Colour&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Animal&amp;nbsp; Weight&lt;/P&gt;&lt;P&gt;Dog&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Blue&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dog&amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;&lt;P&gt;Cat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Black&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Cat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;/P&gt;&lt;P&gt;Fish&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Blue&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Fish&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Dog&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;Cat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Blue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I wish for it to end up as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Merge&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Animal&amp;nbsp; Name&amp;nbsp; Age&amp;nbsp; Colour&amp;nbsp; Weight&lt;/P&gt;&lt;P&gt;Dog&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Blue&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&lt;/P&gt;&lt;P&gt;Cat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Black&amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;/P&gt;&lt;P&gt;Fish&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Blue&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Dog&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Red&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cat&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Blue&amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So some data from the right table may have to match up to many on the left.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently using this code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE Merge AS&lt;BR /&gt;SELECT t1.Animal,&lt;BR /&gt;t1.Name,&lt;BR /&gt;t2.Colour,&lt;BR /&gt;FROM Table1 t1&lt;BR /&gt;LEFT JOIN Table2 t2 ON (t1.animal = t2.animal);&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However when I do this, Instead of keeping the original 5 data entries from table 1, i appear to result in more data entries, and as this is a large data file, i cannot easily single out where or what these extra rows are or where they came from.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 10:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531310#M32943</guid>
      <dc:creator>Jmills</dc:creator>
      <dc:date>2019-01-30T10:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extra data entries when I merge two tables - help with merge</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531319#M32944</link>
      <description>&lt;P&gt;The information you provide does not illustrate your problem.&amp;nbsp; Look at the below code (and please pay particular attention to the formatting of the code, and the use of the code window which is the {i} above post area - code readability is very important):&lt;/P&gt;
&lt;PRE&gt;data have1;
  input animal $ name age colour $;         
datalines;
Dog 1 5 Blue                    
Cat 2 4 Black                  
Fish 3 8 Blue                   
Dog 4 6 Red     
Cat 1 2 Blue
;
run;

data have2;
  input animal $ weight;
datalines;
Dog 7
Cat 9
Fish 2
;
run;

proc sql;
  create table want as
  select t1.*,
         t2.weight
  from   have1 t1
  left join have2 t2
  on     t1.animal=t2.animal;
quit;&lt;/PRE&gt;
&lt;P&gt;If you run this code you will see that in want there is the correct number of rows, and is joined correctly, therefore I cannot replicate your problem.&amp;nbsp; What I suspect is happening is that you have multiple records in have 1, which each match one record on the left, thus duplicating out the left rows, i.e. if Dog appeared twice in the have2 dataset, then that would duplicate each instance of Dog on the left.&lt;/P&gt;
&lt;P&gt;Please also note how I have written the test data in the form of a datastep - not here to type in test data to answer a question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 10:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531319#M32944</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-01-30T10:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extra data entries when I merge two tables - help with merge</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531336#M32945</link>
      <description>&lt;P&gt;Do a data step merge:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=table1;
by animal;
run;

proc sort data=table2;
by animal;
run;

data want;
merge
  table1 (in=a)
  table2 (in=b)
;
by animal;
if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and look at the log. If you get a NOTE about more than one dataset with repeated by values, you have found your culprit.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 11:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531336#M32945</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-30T11:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extra data entries when I merge two tables - help with merge</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531371#M32946</link>
      <description>&lt;P&gt;Double-check your TABLE2.&amp;nbsp; Is it possible that it contains two entries for the same ANIMAL?&amp;nbsp; That would create the problem that you are describing.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jan 2019 14:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extra-data-entries-when-I-merge-two-tables-help-with-merge/m-p/531371#M32946</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-30T14:29:44Z</dc:date>
    </item>
  </channel>
</rss>

