<?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: Merging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367954#M87667</link>
    <description>&lt;P&gt;but there is no 6 in ID in output dataset too....the first column which has 6 is the obs number&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 17 Jun 2017 16:13:08 GMT</pubDate>
    <dc:creator>shynu</dc:creator>
    <dc:date>2017-06-17T16:13:08Z</dc:date>
    <item>
      <title>Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367938#M87661</link>
      <description>&lt;P&gt;data a;&lt;BR /&gt;input m p c;&lt;BR /&gt;cards;&lt;BR /&gt;102 113 114&lt;BR /&gt;102 124 134&lt;BR /&gt;103 114 115&lt;BR /&gt;103 124 135&lt;BR /&gt;104 115 116&lt;BR /&gt;104 125 136&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;input m p c;&lt;BR /&gt;cards;&lt;BR /&gt;102 103 104&lt;BR /&gt;103 104 105&lt;BR /&gt;104 105 106&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data e1;&lt;BR /&gt;merge a b;&lt;BR /&gt;by m;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=e;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;Obs m p c&lt;BR /&gt;1 102 103 104&lt;BR /&gt;2 102 124 134&lt;BR /&gt;3 103 104 105&lt;BR /&gt;4 103 124 135&lt;BR /&gt;5 104 105 106&lt;BR /&gt;6 104 125 136&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input m p c;&lt;BR /&gt;cards;&lt;BR /&gt;102 103 104&lt;BR /&gt;103 104 105&lt;BR /&gt;104 105 106&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;input m p c ;&lt;BR /&gt;cards;&lt;BR /&gt;102 113 114&lt;BR /&gt;102 103 104&lt;BR /&gt;102 124 134&lt;BR /&gt;103 114 115&lt;BR /&gt;103 104 105&lt;BR /&gt;103 124 135&lt;BR /&gt;104 115 116&lt;BR /&gt;104 105 106&lt;BR /&gt;104 125 136&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data e2;&lt;BR /&gt;merge a b;&lt;BR /&gt;by m;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=e;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;Obs m p c&lt;BR /&gt;1 102 113 114&lt;BR /&gt;2 102 103 104&lt;BR /&gt;3 102 124 134&lt;BR /&gt;4 103 114 115&lt;BR /&gt;5 103 104 105&lt;BR /&gt;6 103 124 135&lt;BR /&gt;7 104 115 116&lt;BR /&gt;8 104 105 106&lt;BR /&gt;9 104 125 136&lt;/P&gt;&lt;P&gt;Data A;&lt;BR /&gt;Input ID Name$ Height;&lt;BR /&gt;cards;&lt;BR /&gt;1 A 1&lt;BR /&gt;3 B 2&lt;BR /&gt;5 C 2&lt;BR /&gt;7 D 2&lt;BR /&gt;9 E 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Data B;&lt;BR /&gt;Input ID Name$ Weight;&lt;BR /&gt;cards;&lt;BR /&gt;2 A 2&lt;BR /&gt;4 B 3&lt;BR /&gt;5 C 4&lt;BR /&gt;7 D 5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Data dummy;&lt;BR /&gt;Merge A B;&lt;BR /&gt;by ID;&lt;BR /&gt;run;&lt;BR /&gt;proc print data = dummy;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;Obs ID Name Height Weight&lt;BR /&gt;1 1 A 1 .&lt;BR /&gt;2 2 A . 2&lt;BR /&gt;3 3 B 2 .&lt;BR /&gt;4 4 B . 3&lt;BR /&gt;5 5 C 2 4&lt;BR /&gt;6 7 D 2 5&lt;BR /&gt;7 9 E 2 .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used a simple merge condition in all the 3 codes, but very confused after seeing the ouput.. Can anyone please clarify my confusion?&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2017 11:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367938#M87661</guid>
      <dc:creator>shynu</dc:creator>
      <dc:date>2017-06-17T11:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367939#M87662</link>
      <description>&lt;P&gt;We don't know what is your confusion. You haven't explained what you are confused about. Give us details.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2017 11:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367939#M87662</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-06-17T11:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367940#M87663</link>
      <description>&lt;P&gt;when this type of merging is done we need to get all the obs from both the datasets right? But why is the output varying in all the cases?&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2017 11:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367940#M87663</guid>
      <dc:creator>shynu</dc:creator>
      <dc:date>2017-06-17T11:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367943#M87664</link>
      <description>&lt;P&gt;Your third example is impossible. None of your input datasets contains ID 6.&lt;/P&gt;
&lt;P&gt;Examples 1 &amp;amp; 2 perfectly document the behaviour of datasteps with a by, no conditions, and identically named variables in the input datasets. With identical variables, the sequence of reading the input datasets has an impact on what will end up in the output.&lt;/P&gt;
&lt;P&gt;Having identical variables in a data step merge is therefore (usually) a BAD IDEA.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2017 12:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367943#M87664</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-17T12:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367952#M87665</link>
      <description>&lt;P&gt;If you just walk through the steps involved in merging you can easily see why you are getting the output you posted.&lt;/P&gt;
&lt;P&gt;Let's take the case where M=102.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input m p c;
cards;
102 113 114
102 124 134
;
data b;
  input m p c;
cards;
102 103 104
;
data want ;
  merge a b;
  by m;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So on the first iteration (_N_=1) the MERGE statement will find a record from both A and B. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it first loads the record from A and sets the variables to these values&lt;/P&gt;
&lt;PRE&gt;m=102 p=113 c=114&lt;/PRE&gt;
&lt;P&gt;It then loads the record from B and doing this will replace the values of P and C (I guess it might also replace M but since it is the same value it doesn't change anything). &amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will result in&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;m=102 p=103 c=104&lt;/PRE&gt;
&lt;P&gt;We then reach the end and this is output and the next iteration _n_=2 starts. Now this time there are no more records from B to load so we only load the new recrod from A. &amp;nbsp;So we get&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;m=102 p=124 c=134
&lt;/PRE&gt;
&lt;P&gt;which is then output at the end of the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general it is a bad idea to merge datasets that have common variables that are not part of the BY variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2017 14:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367952#M87665</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-17T14:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367954#M87667</link>
      <description>&lt;P&gt;but there is no 6 in ID in output dataset too....the first column which has 6 is the obs number&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2017 16:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367954#M87667</guid>
      <dc:creator>shynu</dc:creator>
      <dc:date>2017-06-17T16:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367955#M87668</link>
      <description>&lt;P&gt;thank you &amp;nbsp;... Now I understood how it works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2017 16:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/367955#M87668</guid>
      <dc:creator>shynu</dc:creator>
      <dc:date>2017-06-17T16:18:24Z</dc:date>
    </item>
  </channel>
</rss>

