<?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: one to many merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666265#M199316</link>
    <description>&lt;P&gt;When we supply code, we do so in a way that allows direct copy/pasting to your SAS environment (we post the code usein g the "little running man" button). You MUST do this first, to get the &lt;EM&gt;tested&lt;/EM&gt;&amp;nbsp;code (code supplied by senior posters here has been tested in their environment, unless noted otherwise) as-is; after that, you can play around with it and see what consequences each change that you introduce has.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Jul 2020 05:37:46 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-07-01T05:37:46Z</dc:date>
    <item>
      <title>one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666153#M199264</link>
      <description>&lt;P&gt;Hi there -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to merge two dataset by id, but one data has unique id with multiple observations and the second data has unique id with other information that I need. I want to merge Data2 info to Data1 for all the observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data 1&lt;/P&gt;
&lt;P&gt;id name score&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Jo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Jo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;86&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Jo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;54&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; Julia&amp;nbsp; &amp;nbsp;87&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; Julia&amp;nbsp; &amp;nbsp;89&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data 2&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; Age&amp;nbsp; Sex&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; M&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; F&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Outcome file that I want to see&lt;/P&gt;
&lt;P&gt;id name score&amp;nbsp; Age&amp;nbsp; Sex&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Jo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Jo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;86&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Jo&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;54&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; M&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; Julia&amp;nbsp; &amp;nbsp;87&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; Julia&amp;nbsp; &amp;nbsp;89&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran the code below but it seems that it merged with the first observation only.. What am I missing? Thank you.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outcome;
merge Data1 Data2;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jun 2020 16:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666153#M199264</guid>
      <dc:creator>cphd</dc:creator>
      <dc:date>2020-06-30T16:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666155#M199265</link>
      <description>What did the log show? I would expect it to work just as] posted so I suspect your data wasn't sorted and the merge truncated due to an error?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Jun 2020 17:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666155#M199265</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-30T17:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666159#M199266</link>
      <description>Hi Reeza, thank you for your response. &lt;BR /&gt; &lt;BR /&gt;It was successfully merged but there were some missing info in the outcome file, which made me confused. I realized that there are additional information that didn't match to each other. For example, I have id = 4 in data 2 but not in data 1.&lt;BR /&gt;&lt;BR /&gt;So... my question now will be How can I get the outcome file with matched sample only?</description>
      <pubDate>Tue, 30 Jun 2020 17:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666159#M199266</guid>
      <dc:creator>cphd</dc:creator>
      <dc:date>2020-06-30T17:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666160#M199267</link>
      <description>&lt;P&gt;Double check your data2 set to make sure that there are no duplicates of ID. That may also lead to unexpected results.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 17:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666160#M199267</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-30T17:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666162#M199269</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge data1 (in=d1) data2 (in=d2);
by id;

if d1 &amp;amp; d2;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the IN option which creates an indicator variable to indicate a record source.Then if it's from both you keep only those. The join type is considered an 'inner join' in SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2015/05/27/life-saver-tip-for-comparing-proc-sql-join-with-sas-data-step-merge/" target="_blank"&gt;https://blogs.sas.com/content/sastraining/2015/05/27/life-saver-tip-for-comparing-proc-sql-join-with-sas-data-step-merge/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 17:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666162#M199269</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-30T17:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666197#M199287</link>
      <description>&lt;P&gt;You don't actually show what you mean, but I suspect that the issue is that the NEW variables from the ONE dataset that you are trying to add to the MANY dataset already exist.&amp;nbsp; In that case SAS will overwrite the value read from the ONE dataset for the first observation in the group with the values read from the MANY dataset for the 2,3, etc variables in the group.&amp;nbsp; You could use the DROP= dataset option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outcome;
merge Data1(drop=age sex) Data2;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jun 2020 19:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666197#M199287</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-30T19:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666198#M199288</link>
      <description>I followed your code but the log said &lt;BR /&gt;&lt;BR /&gt;"WARNING:Apparent symbolic reference D2 not resolved. "&lt;BR /&gt;&lt;BR /&gt;And it gave me the same result of the entire merged dataset.</description>
      <pubDate>Tue, 30 Jun 2020 19:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666198#M199288</guid>
      <dc:creator>cphd</dc:creator>
      <dc:date>2020-06-30T19:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666200#M199290</link>
      <description>&lt;P&gt;There is huge difference between &amp;lt;&amp;lt;D1 &amp;amp; D2&amp;gt;&amp;gt; which means &amp;lt;&amp;lt;D1 and D2&amp;gt;&amp;gt; and &amp;lt;&amp;lt;D1&amp;amp;D2&amp;gt;&amp;gt; which has a reference to a macro variable named D2.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 19:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666200#M199290</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-30T19:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666204#M199292</link>
      <description>Then you didn't use the code exactly. Post your code and log?&lt;BR /&gt;I suspect Tom is right, you didn't have a space after the &amp;amp;. &lt;BR /&gt;</description>
      <pubDate>Tue, 30 Jun 2020 20:11:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666204#M199292</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-30T20:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666265#M199316</link>
      <description>&lt;P&gt;When we supply code, we do so in a way that allows direct copy/pasting to your SAS environment (we post the code usein g the "little running man" button). You MUST do this first, to get the &lt;EM&gt;tested&lt;/EM&gt;&amp;nbsp;code (code supplied by senior posters here has been tested in their environment, unless noted otherwise) as-is; after that, you can play around with it and see what consequences each change that you introduce has.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 05:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge/m-p/666265#M199316</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-01T05:37:46Z</dc:date>
    </item>
  </channel>
</rss>

