<?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 how to merge three datasets using merge statement or proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-three-datasets-using-merge-statement-or-proc-sql/m-p/21809#M3510</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice!&amp;nbsp; For efficiency's sake (I know, I know - this data is small, but it's a personal obsession...) consider renaming the date variables during the data step concatenation to avoid executing the COALESCE function in the subsequent merge:&lt;/P&gt;&lt;PRE&gt;data dates;
&amp;nbsp; set table2 (rename=(date_1=date))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table3 (rename=(date_2=date)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop=ms);
&amp;nbsp; by pid;
run;
 
data want ;
&amp;nbsp; merge table1 table3 (keep=pid ms) dates;
&amp;nbsp; by pid ;
run;

proc compare data=want compare=table4;
run;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 01 Oct 2011 14:33:44 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2011-10-01T14:33:44Z</dc:date>
    <item>
      <title>how to merge three datasets using merge statement or proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-three-datasets-using-merge-statement-or-proc-sql/m-p/21807#M3508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have 3 tables and I want table 4 exactly in the way I haveshown down the page, objective is no information should be lost.&lt;/P&gt;&lt;P&gt;Problem is, Table2 and Table 3 has 1 column name common and1 column name different i.e. PID and DATE_1 and DATE_2 but Date_1 and Date_2providing same information so I want in table4 only one column with the name asDate.&lt;/P&gt;&lt;P&gt;Table1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="0" cellspacing="0" height="130" style="border-width: initial; border-color: initial; width: 408px; height: 130px; border-style: none;" width="408"&gt;&lt;TBODY&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;PID&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;SEX&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;DOB&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;OCC&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;F&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1985&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;EDU&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;M&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1986&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;IT&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;3&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;M&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1986&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;EDU&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Table2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="0" cellspacing="0" height="96" style="border-width: initial; border-color: initial; width: 263px; height: 96px; border-style: none;" width="263"&gt;&lt;TBODY&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;PID&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;Date_1&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1999&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1999&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Table3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="0" cellspacing="0" height="96" style="border-width: initial; border-color: initial; width: 357px; height: 96px; border-style: none;" width="357"&gt;&lt;TBODY&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;PID&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;Date_2&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;MS&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2002&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;A&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;3&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2000&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="213"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;B&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want this kind of table in sas;&lt;/P&gt;&lt;P&gt;Table4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="0" cellspacing="0" height="163" style="border-width: initial; border-color: initial; width: 473px; height: 163px; border-style: none;" width="473"&gt;&lt;TBODY&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;PID&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;SEX&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="108"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;DOB&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="107"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;OCC&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="102"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;MS&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="109"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;DATE&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;F&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="108"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1985&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="107"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;EDU&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="102"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;Null&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="109"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1999&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;M&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="108"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1986&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="107"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;IT&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="102"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;A&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="109"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1999&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;M&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="108"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1986&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="107"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;IT&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="102"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;A&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="109"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2002&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: inherit; border-color: inherit; border-width: inherit;"&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;3&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="106"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;M&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="108"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;1986&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="107"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;EDU&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="102"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;B&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD style="border-color: inherit; border: inherit; padding-left: 5.4pt; padding-right: 5.4pt;" valign="top" width="109"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;2000&lt;/P&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Waiting for reply its urgent. thnx in advence&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Oct 2011 12:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-three-datasets-using-merge-statement-or-proc-sql/m-p/21807#M3508</guid>
      <dc:creator>sss</dc:creator>
      <dc:date>2011-10-01T12:03:10Z</dc:date>
    </item>
    <item>
      <title>how to merge three datasets using merge statement or proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-three-datasets-using-merge-statement-or-proc-sql/m-p/21808#M3509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is TABLE3.&amp;nbsp; You want to concatenate it with TABLE2 so that you get all the dates, but you also want to merge it by PID so that all records for the same PID get the value of the MS variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input pid sex $ dob occ $ ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 F 1985 EDU&lt;/P&gt;&lt;P&gt;2 M 1986 IT&lt;/P&gt;&lt;P&gt;3 M 1986 EDU&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data table2 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input pid date_1 ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 1999&lt;/P&gt;&lt;P&gt;2 1999&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data table3 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input pid date_2 ms $;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;2 2002 A&lt;/P&gt;&lt;P&gt;3 2000 B&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data table4 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input pid sex $ dob occ $ ms $ date ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 F 1985 EDU . 1999&amp;nbsp; &lt;/P&gt;&lt;P&gt;2 M 1986 IT A 1999 &lt;/P&gt;&lt;P&gt;2 M 1986 IT A 2002&lt;/P&gt;&lt;P&gt;3 M 1986 EDU B 2000&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dates;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set table2 table3 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by pid;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop ms;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge table1 table3 (keep=pid ms) dates ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by pid ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; date = coalesce(date_1,date_2);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc compare data=want compare=table4; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Oct 2011 13:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-three-datasets-using-merge-statement-or-proc-sql/m-p/21808#M3509</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-01T13:11:39Z</dc:date>
    </item>
    <item>
      <title>how to merge three datasets using merge statement or proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-merge-three-datasets-using-merge-statement-or-proc-sql/m-p/21809#M3510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice!&amp;nbsp; For efficiency's sake (I know, I know - this data is small, but it's a personal obsession...) consider renaming the date variables during the data step concatenation to avoid executing the COALESCE function in the subsequent merge:&lt;/P&gt;&lt;PRE&gt;data dates;
&amp;nbsp; set table2 (rename=(date_1=date))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table3 (rename=(date_2=date)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop=ms);
&amp;nbsp; by pid;
run;
 
data want ;
&amp;nbsp; merge table1 table3 (keep=pid ms) dates;
&amp;nbsp; by pid ;
run;

proc compare data=want compare=table4;
run;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Oct 2011 14:33:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-merge-three-datasets-using-merge-statement-or-proc-sql/m-p/21809#M3510</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-10-01T14:33:44Z</dc:date>
    </item>
  </channel>
</rss>

