<?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: Use PROC SQL to merge more than two datasets by one common variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/840742#M82151</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to merge more than two datasets using PROC SQL. I want to merge them by ID (all datasets have this variable in common). These datasets (around 10) all have different number of columns. I've only found a way to join two datasets (example below).&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;SELECT A.*,&amp;nbsp; B.*&lt;BR /&gt;FROM STATES AS A, CITYS AS B&lt;BR /&gt;WHERE A.ID=B.ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why PROC SQL?&lt;/P&gt;
&lt;P&gt;If you want to merge multiple data sets it is much easier in SAS syntax instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge one two three ;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to "join" in SQL then probably should be explicit about the type of join you want to do.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming you only want that observations that have data in all three dataset then use INNER join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from one a 
inner join two b 
  on a.id = b.id
inner join three c
  on a.id = c.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you probably need to also be careful about which variables you select.&amp;nbsp; Using the * shortcut to select all variables will generate notes that ID already exists in the dataset since it will include A.ID and B.ID and C.ID.&amp;nbsp; Since the dataset WANT can only have one variable named ID the first one will be the values that are kept.&amp;nbsp; With an INNER join it does not matter since you are only selecting the joins where the values of the ID variable are the same.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2022 03:45:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-10-26T03:45:53Z</dc:date>
    <item>
      <title>Use PROC SQL to merge more than two datasets by one common variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/840730#M82150</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to merge more than two datasets using PROC SQL. I want to merge them by ID (all datasets have this variable in common). These datasets (around 10) all have different number of columns. I've only found a way to join two datasets (example below).&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;SELECT A.*,&amp;nbsp; B.*&lt;BR /&gt;FROM STATES AS A, CITYS AS B&lt;BR /&gt;WHERE A.ID=B.ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 01:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/840730#M82150</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2022-10-26T01:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Use PROC SQL to merge more than two datasets by one common variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/840742#M82151</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226521"&gt;@ANKH1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to merge more than two datasets using PROC SQL. I want to merge them by ID (all datasets have this variable in common). These datasets (around 10) all have different number of columns. I've only found a way to join two datasets (example below).&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;SELECT A.*,&amp;nbsp; B.*&lt;BR /&gt;FROM STATES AS A, CITYS AS B&lt;BR /&gt;WHERE A.ID=B.ID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why PROC SQL?&lt;/P&gt;
&lt;P&gt;If you want to merge multiple data sets it is much easier in SAS syntax instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge one two three ;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to "join" in SQL then probably should be explicit about the type of join you want to do.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming you only want that observations that have data in all three dataset then use INNER join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from one a 
inner join two b 
  on a.id = b.id
inner join three c
  on a.id = c.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you probably need to also be careful about which variables you select.&amp;nbsp; Using the * shortcut to select all variables will generate notes that ID already exists in the dataset since it will include A.ID and B.ID and C.ID.&amp;nbsp; Since the dataset WANT can only have one variable named ID the first one will be the values that are kept.&amp;nbsp; With an INNER join it does not matter since you are only selecting the joins where the values of the ID variable are the same.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 03:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/840742#M82151</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-26T03:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Use PROC SQL to merge more than two datasets by one common variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/840845#M82156</link>
      <description>proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *&lt;BR /&gt;from &lt;BR /&gt;one  &lt;BR /&gt;  natural join &lt;BR /&gt;two  &lt;BR /&gt;  natural join &lt;BR /&gt;three &lt;BR /&gt;;&lt;BR /&gt;quit;</description>
      <pubDate>Wed, 26 Oct 2022 12:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/840845#M82156</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-10-26T12:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Use PROC SQL to merge more than two datasets by one common variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/841558#M82175</link>
      <description>&lt;P&gt;Thank you! I used the first solution you mentioned.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2022 22:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/841558#M82175</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2022-10-30T22:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Use PROC SQL to merge more than two datasets by one common variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/841591#M82178</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a link with a similar questions, the examples shown here, looks like what you want,&lt;/P&gt;
&lt;P&gt;&lt;A href="http://\https://communities.sas.com/t5/SAS-Programming/Merge-Multiple-tables/td-p/384279" target="_self"&gt;Merge-Multiple-tables&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it will be useful&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 09:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/841591#M82178</guid>
      <dc:creator>himself</dc:creator>
      <dc:date>2022-10-31T09:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Use PROC SQL to merge more than two datasets by one common variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/841725#M82185</link>
      <description>Thanks! The link is not working for some reason.</description>
      <pubDate>Mon, 31 Oct 2022 19:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-PROC-SQL-to-merge-more-than-two-datasets-by-one-common/m-p/841725#M82185</guid>
      <dc:creator>ANKH1</dc:creator>
      <dc:date>2022-10-31T19:24:45Z</dc:date>
    </item>
  </channel>
</rss>

