<?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: Merge Datasets Together in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/632452#M187518</link>
    <description>Thank you!</description>
    <pubDate>Mon, 16 Mar 2020 15:05:19 GMT</pubDate>
    <dc:creator>luvscandy27</dc:creator>
    <dc:date>2020-03-16T15:05:19Z</dc:date>
    <item>
      <title>Merge Datasets Together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631719#M187191</link>
      <description>&lt;DIV class="gE iv gt"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class=""&gt;
&lt;DIV id=":6s" class="ii gt"&gt;
&lt;DIV id=":6r" class="a3s aXjCH "&gt;
&lt;DIV dir="ltr"&gt;I have two data sets (data below) and I am trying to merge the data together using proc sql code below. When I merge the two&lt;BR /&gt;tables I get all of the dates from Id 3 and only the review dates for ID 1 and 2. I have tried to join the two tables using left, right, inner and full join and it seems as if I am getting the same results.&amp;nbsp;What I would like to do is merge by ID and keep all of the dates for each ID.&lt;/DIV&gt;
&lt;DIV dir="ltr"&gt;&lt;BR /&gt;Can someone assist me with this please?&lt;/DIV&gt;
&lt;DIV dir="ltr"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV dir="ltr"&gt;
&lt;P&gt;data test1;&lt;BR /&gt;infile datalines delimiter = ',';&lt;BR /&gt;input ID START:mmddyy10. REVIEWCOMPLETE: mmddyy10. HEALTHDATE:mmddyy10. HEALTHDATEEND:mmddyy10.&lt;BR /&gt;END: mmddyy10. CERTIFYDATE: mmddyy10.; &lt;BR /&gt;format START REVIEWCOMPLETE HEALTHDATE HEALTHDATEEND END CERTIFYDATE mmddyy10. ;&lt;BR /&gt;datalines; &lt;BR /&gt;1, , , , , , , &lt;BR /&gt;2, , , , , , , &lt;BR /&gt;3,01/16/2019, 01/23/2019, 01/26/2019, 01/26/2019, 01/26/2019,01/26/2019, &lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data test2;&lt;BR /&gt;infile datalines delimiter = ',';&lt;BR /&gt;input ID START:mmddyy10. REVIEW:mmddyy10. REVIEWCOMPLETE: mmddyy10. HEALTHDATE:mmddyy10. HEALTHDATEEND:mmddyy10.&lt;BR /&gt;END: mmddyy10. CERTIFYDATE: mmddyy10.; &lt;BR /&gt;format START REVIEW REVIEWCOMPLETE HEALTHDATE HEALTHDATEEND END CERTIFYDATE mmddyy10. ;&lt;BR /&gt;datalines; &lt;BR /&gt;1,01/17/2020,01/29/2020,01/30/2020, , , , ,&lt;BR /&gt;2,01/10/2020,01/24/2020, , , , , ,&lt;BR /&gt;3, , , , , , , ,&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql; &lt;BR /&gt;create table table3 as&lt;BR /&gt;select * from test1 as a inner join test2 as b&lt;BR /&gt;on a.id = b.id;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 12 Mar 2020 22:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631719#M187191</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-03-12T22:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Datasets Together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631722#M187193</link>
      <description>&lt;P&gt;Do NOT use the asterisk in sql joins, make an explicit list, and use the coalesce() function to overwrite only the missing values.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 22:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631722#M187193</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-12T22:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Datasets Together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631728#M187195</link>
      <description>&lt;P&gt;When I make an explicit list I get the following error. Also,&amp;nbsp;I want to keep the missing dates where missing dates should be therefore I don't think the coalesce function is what I need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql; &lt;BR /&gt;	create table table3 as&lt;BR /&gt;	select ID, START,REVIEW, REVIEWCOMPLETE, HEALTHDATE, HEALTHDATEEND, END, CERTIFYDATE&lt;BR /&gt;	from test1 as a inner join test2 as b&lt;BR /&gt;	on a.id = b.id;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;DIV id="sasLogError1_1584052374087" class="sasError"&gt;ERROR: Ambiguous reference, column ID is in more than one table.&lt;/DIV&gt;
&lt;DIV id="sasLogError2_1584052374087" class="sasError"&gt;ERROR: Ambiguous reference, column START is in more than one table.&lt;/DIV&gt;
&lt;DIV id="sasLogError3_1584052374087" class="sasError"&gt;ERROR: Ambiguous reference, column REVIEWCOMPLETE is in more than one table.&lt;/DIV&gt;
&lt;DIV id="sasLogError4_1584052374087" class="sasError"&gt;ERROR: Ambiguous reference, column HEALTHDATE is in more than one table.&lt;/DIV&gt;
&lt;DIV id="sasLogError5_1584052374087" class="sasError"&gt;ERROR: Ambiguous reference, column HEALTHDATEEND is in more than one table.&lt;/DIV&gt;
&lt;DIV id="sasLogError6_1584052374087" class="sasError"&gt;ERROR: Ambiguous reference, column END is in more than one table.&lt;/DIV&gt;
&lt;DIV id="sasLogError7_1584052374087" class="sasError"&gt;ERROR: Ambiguous reference, column CERTIFYDATE is in more than one table.&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1584052374087" class="sasNote"&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76 quit;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 12 Mar 2020 22:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631728#M187195</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-03-12T22:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Datasets Together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631767#M187208</link>
      <description>You need to specify which variable is coming from where, especially when it's in more than one table. &lt;BR /&gt;&lt;BR /&gt;select a.ID, a.Start, a.reviewComplete etc&lt;BR /&gt;&lt;BR /&gt;Are you sure you want a merge and not an APPEND given the number of variables that are the same in the data set?</description>
      <pubDate>Fri, 13 Mar 2020 02:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631767#M187208</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-13T02:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Datasets Together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631774#M187212</link>
      <description>&lt;P&gt;1.&lt;EM&gt; &amp;gt;Also,&amp;nbsp;I want to keep the missing dates where missing dates should be therefore I don't think the coalesce function is what I need.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Coalesce&lt;SPAN&gt;&amp;nbsp;does want you asked in your question.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;What does&amp;nbsp;&amp;nbsp;&lt;EM&gt;&amp;nbsp;missing dates should be&amp;nbsp; &amp;nbsp;&lt;/EM&gt; mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. A data step with an &lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p18w3br45er2qun1r8sfmm4grjyr.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;update&lt;/A&gt; statement might be what you want.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data TABLE3; update TABLE1 TABLE2; by ID; run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 02:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/631774#M187212</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-13T02:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Datasets Together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/632246#M187431</link>
      <description>&lt;P&gt;In SQL, you need to use the coalesce() function. Here is code with both (SQL and data step) solutions, and a check step to make sure both yield the same result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
infile datalines delimiter = ',' dsd;
input ID START:mmddyy10. REVIEWCOMPLETE: mmddyy10. HEALTHDATE:mmddyy10. HEALTHDATEEND:mmddyy10.
END: mmddyy10. CERTIFYDATE: mmddyy10.; 
format START REVIEWCOMPLETE HEALTHDATE HEALTHDATEEND END CERTIFYDATE yymmddd10. ;
datalines; 
1, , , , , , , 
2, , , , , , , 
3,01/16/2019, 01/23/2019, 01/26/2019, 01/26/2019, 01/26/2019,01/26/2019, 
;
 
data test2;
infile datalines delimiter = ',' dsd;
input ID START:mmddyy10. REVIEW:mmddyy10. REVIEWCOMPLETE: mmddyy10. HEALTHDATE:mmddyy10. HEALTHDATEEND:mmddyy10.
END: mmddyy10. CERTIFYDATE: mmddyy10.; 
format START REVIEW REVIEWCOMPLETE HEALTHDATE HEALTHDATEEND END CERTIFYDATE yymmddd10. ;
datalines; 
1,01/17/2020,01/29/2020,01/30/2020, , , , ,
2,01/10/2020,01/24/2020, , , , , ,
3, , , , , , , ,
;

proc sql;
create table want1 as
select
  t1.id,
  coalesce(t1.start,t2.start) as start format=yymmddd10.,
  t2.review,
  coalesce(t1.reviewcomplete,t2.reviewcomplete) as reviewcomplete format=yymmddd10.,
  coalesce(t1.healthdate,t2.healthdate) as healthdate format=yymmddd10.,
  coalesce(t1.healthdateend,t2.healthdateend) as healthdateend format=yymmddd10.,
  coalesce(t1.end,t2.end) as end format=yymmddd10.,
  coalesce(t1.certifydate,t2.certifydate) as certifydate format=yymmddd10.
from test1 t1 full join test2 t2
on t1.id = t2.id;
quit;

data want2;
update test1 test2;
by id;
run;

proc compare base=want1 compare=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, the data step solution (as it is most often in SAS) is the most simple one.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 11:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/632246#M187431</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-15T11:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Merge Datasets Together</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/632452#M187518</link>
      <description>Thank you!</description>
      <pubDate>Mon, 16 Mar 2020 15:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-Datasets-Together/m-p/632452#M187518</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-03-16T15:05:19Z</dc:date>
    </item>
  </channel>
</rss>

