<?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 Merge step overwriting shared vars? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-step-overwriting-shared-vars/m-p/281534#M57114</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets that both have ID and a number of other variables. Some of these variables exist on both datasets. I sorted both of them by ID and merged, and I thought I had dropped all vars from Dataset 1 that also existed in Dataset 2 (I wanted the values from Dataset 2 of those variables), however, there is a variable I forgot to drop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a rule for merges in terms of which dataset would overwrite which if two merging datasets share a variable (but not the variable that is being merged on).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 1&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; Shared_var&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; abc&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 2&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; Shared_var&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xyz&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ie, if I sort both and merge them on ID only, which values of shared_var would appear in the output dataset?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2016 18:03:27 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2016-06-30T18:03:27Z</dc:date>
    <item>
      <title>Merge step overwriting shared vars?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-step-overwriting-shared-vars/m-p/281534#M57114</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets that both have ID and a number of other variables. Some of these variables exist on both datasets. I sorted both of them by ID and merged, and I thought I had dropped all vars from Dataset 1 that also existed in Dataset 2 (I wanted the values from Dataset 2 of those variables), however, there is a variable I forgot to drop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a rule for merges in terms of which dataset would overwrite which if two merging datasets share a variable (but not the variable that is being merged on).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 1&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; Shared_var&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; abc&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset 2&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; Shared_var&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;def&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xyz&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ie, if I sort both and merge them on ID only, which values of shared_var would appear in the output dataset?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 18:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-step-overwriting-shared-vars/m-p/281534#M57114</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2016-06-30T18:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merge step overwriting shared vars?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-step-overwriting-shared-vars/m-p/281542#M57117</link>
      <description>&lt;P&gt;There is a rule:&amp;nbsp; whichever value was read last.&amp;nbsp; But that rule is simple only when the merge is one-to-one.&amp;nbsp; In that case, the value you get depends on the order in the MERGE statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;merge a b;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value of common variables (for a one-to-one merge) comes from data set B.&amp;nbsp; SAS reads a value from data set A, then reads a value from data set B.&amp;nbsp; The value from B is read last, and overwrites the value read from data set A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is a mismatch, and an ID appears only in data set A but not in data set B, the value will be the one found in data set A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a many-to-one merge, the situation is more complex.&amp;nbsp; SAS never reads the same observation twice.&amp;nbsp; It reads each observation just once, and retains what it has read.&amp;nbsp; If that's the situation you're facing, I can go into more detail.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 18:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-step-overwriting-shared-vars/m-p/281542#M57117</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-30T18:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merge step overwriting shared vars?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-step-overwriting-shared-vars/m-p/281543#M57118</link>
      <description>&lt;P&gt;It was a one-to-one merge.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 19:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-step-overwriting-shared-vars/m-p/281543#M57118</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2016-06-30T19:04:00Z</dc:date>
    </item>
  </channel>
</rss>

