<?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: How to combine ten data sets using PROC SQL efficiently in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404924#M279091</link>
    <description>&lt;P&gt;Thanks a lot. Made those changes (adding i.id and j.id in the coalesce and adding order by) and the output looks much better. Only one question, why idno 5 is coming up twice ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-10-17 at 2.29.27 PM.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15962i8CD456C464AE74B4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2017-10-17 at 2.29.27 PM.png" alt="Screen Shot 2017-10-17 at 2.29.27 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Oct 2017 18:31:29 GMT</pubDate>
    <dc:creator>shihabur</dc:creator>
    <dc:date>2017-10-17T18:31:29Z</dc:date>
    <item>
      <title>How to combine ten data sets using PROC SQL efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404634#M279085</link>
      <description>&lt;P&gt;I have ten data sets and all of them has customer_id variable in common. I know if we have three data sets we can do something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table example as
select a.ID, b.*, c.* from
temp a full join temp2 b
on a.id = b.id
full join temp3 c
on a.id = c.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But for ten or more dataset it will get really complex. So is there any other efficient way to do this ?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 23:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404634#M279085</guid>
      <dc:creator>shihabur</dc:creator>
      <dc:date>2017-10-16T23:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine ten data sets using PROC SQL efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404637#M279086</link>
      <description>&lt;P&gt;Try a data step merge instead?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 23:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404637#M279086</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-16T23:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine ten data sets using PROC SQL efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404712#M279087</link>
      <description>&lt;P&gt;Please define "efficient"? It sounds like you mean less complex. And yes, it might be easier with a data step merge as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;suggests. Bare in mind you might need to pre-sort the data sets - all need to be sorted on the BY variable which is not a requirement for SQL joins).&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 09:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404712#M279087</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-10-17T09:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine ten data sets using PROC SQL efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404872#M279088</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;you are right. I meant less complex.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 16:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404872#M279088</guid>
      <dc:creator>shihabur</dc:creator>
      <dc:date>2017-10-17T16:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine ten data sets using PROC SQL efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404915#M279089</link>
      <description>&lt;P&gt;Despite having to sort every data set, merging is providing the desired result for me. Below is the code I tried to compare results between proc sql and data step merging.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*created 10 data sets*/

data temp1;
input id x1 x2;
cards;
1 25 37
2 35 .
3 44 97
;
run;

data temp2;
input id var1 var2;
cards;
2 65 37
3 .  47
5 34 97
;
run;

data temp3;
input id xx1 xx2;
cards;
3 55 37
5 25 47
4 .  97
;
run;

data temp4;
input id var3 var4;
cards;
6 25 37
7 35 47
9 .  .
;
run;

data temp5;
input id var5 var6;
cards;
5 65 37
6 85 47
9 34 97
;
run;

data temp6;
input id xx3 xx4;
cards;
11 55 37
13 25 47
14 64 97
;
run;

data temp7;
input id xx5 xx6;
cards;
11 25 .
15 35 47
16 44 97
;
run;

data temp8;
input id x3 x4;
cards;
12 65 .
15 85 47
16 .  97
;
run;

data temp9;
input id x5 x6;
cards;
17 55 37
18 25 47
19 64 97
;
run;

data temp10;
input id x7 x8;
cards;
17 .  .
20 25 37
22 24 97
;
run;

/*not including the proc sort here */

data new;
merge temp1 temp2 temp3 temp4 temp5 temp6 temp7 temp8 temp9 temp10;
by id;
run;

proc print data = new;
title 'merged 10 data sets';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The above code produces below output, which seems like what I want.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-10-17 at 1.44.43 PM.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15960i5A8D3495CC69AD2A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2017-10-17 at 1.44.43 PM.png" alt="Screen Shot 2017-10-17 at 1.44.43 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But the PROC SQL output looks messed up. I ran the same code for joining 3 tables and then the output was fine. But for 10 tables the output looks very weird. I am just experimenting with proc sql and want to know how to produce similar output like the data step merge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title "proc sql full join";
proc sql;
select coalesce(a.id, b.id, c.id, d.id, e.id, f.id, g.id, h.id) as idno, a.*, b.*, c.*, d.*, e.*, f.*, g.*, h.* , i.*, j.*
from temp1 a Full Join temp2 b on a.id = b.id
Full Join temp3 c on b.id = c.id
Full Join temp4 d on c.id = d.id
Full Join temp5 e on d.id = e.id
Full Join temp6 f on e.id = f.id
Full Join temp7 g on f.id = g.id
Full Join temp8 h on g.id = h.id
Full Join temp9 i on h.id = i.id
Full Join temp10 j on i.id = j.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the output is below.The idno column is not sorted in ascending order and it is also omitting some of the id numbers from 17,18,19,20,22 . Also idno 5 is repeated twice. Can you please tell me what's wrong here ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-10-17 at 1.51.33 PM.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15961iC33F12001BCD9307/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2017-10-17 at 1.51.33 PM.png" alt="Screen Shot 2017-10-17 at 1.51.33 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 18:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404915#M279089</guid>
      <dc:creator>shihabur</dc:creator>
      <dc:date>2017-10-17T18:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine ten data sets using PROC SQL efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404916#M279090</link>
      <description>&lt;P&gt;17, 18, 19, 20 &amp;amp; 22 is missing just in the idno column, because you are omitting the i.id and j.id in your coalesce argument.&lt;/P&gt;
&lt;P&gt;SQL doen't necessarily output in sorted order, even on the join column.&lt;/P&gt;
&lt;P&gt;Add an ORDER BY clause to have in the order you want.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 18:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404916#M279090</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-10-17T18:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine ten data sets using PROC SQL efficiently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404924#M279091</link>
      <description>&lt;P&gt;Thanks a lot. Made those changes (adding i.id and j.id in the coalesce and adding order by) and the output looks much better. Only one question, why idno 5 is coming up twice ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2017-10-17 at 2.29.27 PM.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15962i8CD456C464AE74B4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2017-10-17 at 2.29.27 PM.png" alt="Screen Shot 2017-10-17 at 2.29.27 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 18:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-ten-data-sets-using-PROC-SQL-efficiently/m-p/404924#M279091</guid>
      <dc:creator>shihabur</dc:creator>
      <dc:date>2017-10-17T18:31:29Z</dc:date>
    </item>
  </channel>
</rss>

