<?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: Proc SQL - Merge 4 tables into 1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288481#M59500</link>
    <description>&lt;P&gt;In addition to whats been said above, code formatting is very important to other people who might read your code - in fact probably more important that the code itself nowadays. &amp;nbsp;Consistent indetation, casing and such like makes reading far easier. &amp;nbsp;Also I would add that using the * notation is probably not a good idea, this means take all variables from that table - which may work or you may get variables in multiple datasets, or you may have different variables next time. &amp;nbsp;For instance if your code runs, then you will get warnings as CONFIGURATION is in at least A and B. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make your code clearer and easier to maintain (also more efficient), specify what variables are to be taken from each table. &amp;nbsp;If they are to be combined, use COALESCE() function.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table CASE_STUDY2 as
  select  COALESCE(A.CONFIGURATION,B.CONFIGURATION) as CONFIGURATION,
          COALESCE(A.STORE_POSTCODE,B.POST_CODE,C.POST_CODE,D.POST_CODE) as POST_CODE
  from    T.POS_1 as A,
          T.POS_2 as B,
          T.POS_3 as C,
          T.POS_4 as D
  where   A.CONFIGURATION=B.CONFIGURATION
    and   C.CONFIGURATION=D.CONFIGURATION 
    and   A.STORE_POSTCODE=B.POST_CODE  
    and   C.POST_CODE=D.POST_CODE 
    and   A.CUSTOMER_POSTCODE=B.CUSTOMER_POSTCODE
    and   C.CUSTOMER_POSTCODE=D.CUSTOMER_POSTCODE
  order by T.POS_1;
quit;&lt;/PRE&gt;</description>
    <pubDate>Mon, 01 Aug 2016 08:51:47 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-08-01T08:51:47Z</dc:date>
    <item>
      <title>Proc SQL - Merge 4 tables into 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288456#M59494</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;
&lt;P&gt;this the code and i am not able to merge 4 tables into 1 table .i just wanted to combine 4 tables into 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table case study2 as&lt;BR /&gt;select A.*,B.*,C.*,D.*&lt;BR /&gt;FROM T.Pos_1 as A,T.Pos_2 as B,T.pos_3 as C,T.pos_4 as D&lt;BR /&gt;WHERE A.Configuration=B.Configuration=C.Configuration=D.Configuration and A.Store_Postcode=B.Post_code=C.Post_code=D.Post_code and&lt;BR /&gt;A.Customer_Postcode=B.Customer_Postcode=C.Customer_Postcode=D.Customer_Postcode&lt;BR /&gt;order by T.Pos_1;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;error&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;xpecting a '.'.&lt;/P&gt;
&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 07:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288456#M59494</guid>
      <dc:creator>Prateek1</dc:creator>
      <dc:date>2016-08-01T07:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Merge 4 tables into 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288457#M59495</link>
      <description>&lt;P&gt;Your where conditions are incorrect. For starters you should have only one equal sign.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should specify the join type and use ON instead of Where. It's usually faster.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 07:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288457#M59495</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-01T07:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Merge 4 tables into 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288462#M59496</link>
      <description>You need to insert an AND between each pair of join conditions, you can't combine them the way you do, even if you think they are related.</description>
      <pubDate>Mon, 01 Aug 2016 07:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288462#M59496</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-08-01T07:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Merge 4 tables into 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288463#M59497</link>
      <description>&lt;P&gt;Also the table name you are creating ("case study") is not a valid sas name.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 08:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288463#M59497</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2016-08-01T08:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Merge 4 tables into 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288481#M59500</link>
      <description>&lt;P&gt;In addition to whats been said above, code formatting is very important to other people who might read your code - in fact probably more important that the code itself nowadays. &amp;nbsp;Consistent indetation, casing and such like makes reading far easier. &amp;nbsp;Also I would add that using the * notation is probably not a good idea, this means take all variables from that table - which may work or you may get variables in multiple datasets, or you may have different variables next time. &amp;nbsp;For instance if your code runs, then you will get warnings as CONFIGURATION is in at least A and B. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make your code clearer and easier to maintain (also more efficient), specify what variables are to be taken from each table. &amp;nbsp;If they are to be combined, use COALESCE() function.&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table CASE_STUDY2 as
  select  COALESCE(A.CONFIGURATION,B.CONFIGURATION) as CONFIGURATION,
          COALESCE(A.STORE_POSTCODE,B.POST_CODE,C.POST_CODE,D.POST_CODE) as POST_CODE
  from    T.POS_1 as A,
          T.POS_2 as B,
          T.POS_3 as C,
          T.POS_4 as D
  where   A.CONFIGURATION=B.CONFIGURATION
    and   C.CONFIGURATION=D.CONFIGURATION 
    and   A.STORE_POSTCODE=B.POST_CODE  
    and   C.POST_CODE=D.POST_CODE 
    and   A.CUSTOMER_POSTCODE=B.CUSTOMER_POSTCODE
    and   C.CUSTOMER_POSTCODE=D.CUSTOMER_POSTCODE
  order by T.POS_1;
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Aug 2016 08:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288481#M59500</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-01T08:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Merge 4 tables into 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288482#M59501</link>
      <description>&lt;P&gt;Since (at least) Configuration, Post_code and Customer_Postcode are present in more than one input dataset, your&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select A.*,B.*,C.*,D.*&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will also cause an ERROR by SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you start easy by joining 2 tables, and once that is solved, add more tables into the mix.&lt;/P&gt;
&lt;P&gt;Less code from the beginning will make it easier for you to make sense of the ERROR messages and debug this.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 08:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288482#M59501</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-01T08:52:42Z</dc:date>
    </item>
    <item>
      <title>proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288554#M59525</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;how to merge 4 csv files into 1 by proc sql ??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 12:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288554#M59525</guid>
      <dc:creator>Prateek1</dc:creator>
      <dc:date>2016-08-01T12:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288557#M59526</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't merge CSV files. &amp;nbsp;CSV files are imported into SAS datasets, then those SAS datasets are combined following certain joining criteria, as given in the examples above.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 12:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288557#M59526</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-01T12:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288561#M59528</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89805"&gt;@Prateek1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;hi,&lt;/P&gt;
&lt;P&gt;how to merge 4 csv files into 1 by proc sql ??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;1. Import data into SAS&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Define how you want to combine files&lt;/P&gt;
&lt;P&gt;See the examples here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1tgk0uanvisvon1r26lc036k0w7.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1tgk0uanvisvon1r26lc036k0w7.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 12:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Merge-4-tables-into-1/m-p/288561#M59528</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-01T12:33:10Z</dc:date>
    </item>
  </channel>
</rss>

