<?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: Conditional merging of two datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248746#M46747</link>
    <description>Try SQL full/left join, and use the coalesce() function on your tos1&amp;amp;2 columns (and mspcd if you are doing a full join).</description>
    <pubDate>Mon, 08 Feb 2016 21:44:26 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-02-08T21:44:26Z</dc:date>
    <item>
      <title>Conditional merging of two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248737#M46745</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm struggling with merging two tables sucessfully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table 1 looks like this :&lt;/P&gt;
&lt;P&gt;mapcd &amp;nbsp; tos1 &amp;nbsp; &amp;nbsp; &amp;nbsp; tos2&lt;/P&gt;
&lt;P&gt;300 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;facop &amp;nbsp; &amp;nbsp;surg&lt;/P&gt;
&lt;P&gt;355 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;anc &amp;nbsp; &amp;nbsp; &amp;nbsp; mater&lt;/P&gt;
&lt;P&gt;467 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;anc &amp;nbsp; &amp;nbsp; &amp;nbsp; hh/hpc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table 2 looks like this:&lt;/P&gt;
&lt;P&gt;mapcd &amp;nbsp; tos1 &amp;nbsp; &amp;nbsp; &amp;nbsp; tos2&lt;/P&gt;
&lt;P&gt;274&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; facip &amp;nbsp; &amp;nbsp; medic&lt;/P&gt;
&lt;P&gt;275&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; facip &amp;nbsp; &amp;nbsp; mater&lt;/P&gt;
&lt;P&gt;300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;355&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I want my resulting table to look like this;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;mapcd &amp;nbsp; tos1 &amp;nbsp; &amp;nbsp; &amp;nbsp; tos2&lt;/P&gt;
&lt;P&gt;274&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; facip &amp;nbsp; &amp;nbsp; medic&lt;/P&gt;
&lt;P&gt;275&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; facip &amp;nbsp; &amp;nbsp; mater&lt;/P&gt;
&lt;P&gt;300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;facop &amp;nbsp; &amp;nbsp;surg&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;355&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;anc &amp;nbsp; &amp;nbsp; &amp;nbsp; mater&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;essentially, i want to update table 2 with what's in table 1 based on the common variable "mapcd". I only want this done where tos1 and tos2 are missing in table 2 and also don't want to lose whats already in table 2.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm aware that the variables are the same in both tables. Do I one to rename them in one table in order for it?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I've tried a simple merge in a data step, update in proc sql and none are working for me.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any help would be appreciated.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 21:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248737#M46745</guid>
      <dc:creator>jazzblues24</dc:creator>
      <dc:date>2016-02-08T21:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merging of two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248746#M46747</link>
      <description>Try SQL full/left join, and use the coalesce() function on your tos1&amp;amp;2 columns (and mspcd if you are doing a full join).</description>
      <pubDate>Mon, 08 Feb 2016 21:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248746#M46747</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-02-08T21:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merging of two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248762#M46755</link>
      <description>&lt;P&gt;Are ANY of your MAPCD values in dataset2 ever duplicated?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 22:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248762#M46755</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-02-08T22:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merging of two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248779#M46756</link>
      <description>&lt;P&gt;yes there are several duplicates along with more variables&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 23:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248779#M46756</guid>
      <dc:creator>jazzblues24</dc:creator>
      <dc:date>2016-02-08T23:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merging of two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248780#M46757</link>
      <description>&lt;P&gt;Thanks. I got it to work. Just in case anyone else refers to this in the future, here's what I used&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *,&lt;BR /&gt;coalesce (a.tos1,b.tos1) as tostos1,&lt;BR /&gt;coalesce (a.tos2,b.tos2) as tostos2&lt;BR /&gt;from out.table2 A left join out.table1 B&lt;BR /&gt;on a.mapcd = b.mapcd;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 23:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248780#M46757</guid>
      <dc:creator>jazzblues24</dc:creator>
      <dc:date>2016-02-08T23:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional merging of two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248781#M46758</link>
      <description>&lt;P&gt;Is this not a straightforward DATA step? &amp;nbsp;Assuming your data sets are already sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge table2 (in=in2) table1 (in=in1);&lt;/P&gt;
&lt;P&gt;by mapcd;&lt;/P&gt;
&lt;P&gt;if in2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just be sure to mention TABLE2 first, and any TABLE1 values will overwrite the TABLE2 values. &amp;nbsp;This also depends on the situation being a 1-to-1 merge, not many-to-1.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2016 00:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-merging-of-two-datasets/m-p/248781#M46758</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-02-09T00:11:42Z</dc:date>
    </item>
  </channel>
</rss>

