<?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 datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236152#M43247</link>
    <description>&lt;P&gt;Well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data1&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data2&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp;16&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp;17&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Interleaving:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
&amp;nbsp; set data1 data2;
&amp;nbsp; by ID;
run;&lt;/PRE&gt;
&lt;P&gt;Would give:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp;16&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; 17&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works a bit like looping over the distinct by variables, so loop 1 is for ID=1, take all records from data1 where ID=1, then all records from data2 where ID=1, next loop do ID=2 etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Merging:&lt;/P&gt;
&lt;PRE&gt;data want;
  merge data1 data2 (rename=(result=result2));
  by ID:
run;&lt;/PRE&gt;
&lt;P&gt;Would give:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp;RESULT &amp;nbsp; RESULT2&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;16&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above, as the two datasets have a variable the same, the second has to be renamed. &amp;nbsp;What happens is the data from the second data is merged onto the first, so where data1.id=1 and data2.id=1 then that row comes out, then if data1.id=2 and data2.id=2, and so on. &amp;nbsp;As ID=2 does not exist in the second data then that variable is set to missing, same for 3 as that variable does not appear in data1. &amp;nbsp;The ID variable is always present (although missing is also possible) as it is the merge key variable.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Nov 2015 09:47:06 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-11-24T09:47:06Z</dc:date>
    <item>
      <title>merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236144#M43243</link>
      <description>&lt;P&gt;&lt;SPAN&gt;How interleaving is different from Merging?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Help me with an example.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 09:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236144#M43243</guid>
      <dc:creator>KafeelBasha</dc:creator>
      <dc:date>2015-11-24T09:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236150#M43245</link>
      <description>&lt;P&gt;Please see these examples from SAS documentation:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001318366.htm" target="_blank"&gt;Interleaving&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001318494.htm" target="_blank"&gt;Merging (here: Match-Merging)&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 24 Nov 2015 09:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236150#M43245</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-24T09:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236151#M43246</link>
      <description>&lt;P&gt;The documentation provides very detailed explanations with examples. I believe this is more than any of us can give you as an answer in this forum.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1tgk0uanvisvon1r26lc036k0w7.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1tgk0uanvisvon1r26lc036k0w7.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you read through the docu. Come back if there is something still not clear to you after reading the docu and ask your question(s) refering to what's in the docu.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 09:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236151#M43246</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-24T09:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: merging datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236152#M43247</link>
      <description>&lt;P&gt;Well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data1&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 10&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data2&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp;16&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp;17&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Interleaving:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
&amp;nbsp; set data1 data2;
&amp;nbsp; by ID;
run;&lt;/PRE&gt;
&lt;P&gt;Would give:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp;16&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; 17&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works a bit like looping over the distinct by variables, so loop 1 is for ID=1, take all records from data1 where ID=1, then all records from data2 where ID=1, next loop do ID=2 etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Merging:&lt;/P&gt;
&lt;PRE&gt;data want;
  merge data1 data2 (rename=(result=result2));
  by ID:
run;&lt;/PRE&gt;
&lt;P&gt;Would give:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp;RESULT &amp;nbsp; RESULT2&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;16&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above, as the two datasets have a variable the same, the second has to be renamed. &amp;nbsp;What happens is the data from the second data is merged onto the first, so where data1.id=1 and data2.id=1 then that row comes out, then if data1.id=2 and data2.id=2, and so on. &amp;nbsp;As ID=2 does not exist in the second data then that variable is set to missing, same for 3 as that variable does not appear in data1. &amp;nbsp;The ID variable is always present (although missing is also possible) as it is the merge key variable.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 09:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merging-datasets/m-p/236152#M43247</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-24T09:47:06Z</dc:date>
    </item>
  </channel>
</rss>

