<?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 SQL UNION operator in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537320#M147765</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to join two data sets using proc SQL and both the data sets have different columns is there a way I can make my code work.See example below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CARS1 AS SELECT&lt;BR /&gt;CYLINDERS&lt;BR /&gt;,MAKE&lt;BR /&gt;,MSRP&lt;BR /&gt;,HORSEPOWER&lt;BR /&gt;,INVOICE&lt;BR /&gt;,LENGTH&lt;/P&gt;&lt;P&gt;FROM SASHELP.CARS&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CARS2 AS SELECT&lt;BR /&gt;ORIGIN&lt;BR /&gt;,TYPE&lt;BR /&gt;,WEIGHT&lt;BR /&gt;,MAKE&lt;BR /&gt;,MSRP&lt;BR /&gt;,HORSEPOWER&lt;BR /&gt;FROM SASHELP.CARS&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CARS3 AS SELECT&lt;BR /&gt;MAKE&lt;BR /&gt;,MSRP&lt;BR /&gt;,HORSEPOWER&lt;BR /&gt;,INVOICE&lt;BR /&gt;,LENGTH&lt;BR /&gt;,CYLINDERS&lt;BR /&gt;FROM CARS1&lt;BR /&gt;UNION ALL&lt;BR /&gt;SELECT&lt;BR /&gt;MAKE&lt;BR /&gt;,MSRP&lt;BR /&gt;,HORSEPOWER&lt;BR /&gt;,ORIGIN&lt;BR /&gt;,TYPE&lt;BR /&gt;,WEIGHT&lt;BR /&gt;FROM CARS2&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Column 4 from the first contributor of UNION ALL is not the same type as its counterpart from the second.&lt;BR /&gt;ERROR: Column 5 from the first contributor of UNION ALL is not the same type as its counterpart from the second.&lt;/P&gt;&lt;P&gt;I want to use Proc SQL only&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Kajal&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Feb 2019 06:35:39 GMT</pubDate>
    <dc:creator>kajal_30</dc:creator>
    <dc:date>2019-02-21T06:35:39Z</dc:date>
    <item>
      <title>SQL UNION operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537320#M147765</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to join two data sets using proc SQL and both the data sets have different columns is there a way I can make my code work.See example below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CARS1 AS SELECT&lt;BR /&gt;CYLINDERS&lt;BR /&gt;,MAKE&lt;BR /&gt;,MSRP&lt;BR /&gt;,HORSEPOWER&lt;BR /&gt;,INVOICE&lt;BR /&gt;,LENGTH&lt;/P&gt;&lt;P&gt;FROM SASHELP.CARS&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CARS2 AS SELECT&lt;BR /&gt;ORIGIN&lt;BR /&gt;,TYPE&lt;BR /&gt;,WEIGHT&lt;BR /&gt;,MAKE&lt;BR /&gt;,MSRP&lt;BR /&gt;,HORSEPOWER&lt;BR /&gt;FROM SASHELP.CARS&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CARS3 AS SELECT&lt;BR /&gt;MAKE&lt;BR /&gt;,MSRP&lt;BR /&gt;,HORSEPOWER&lt;BR /&gt;,INVOICE&lt;BR /&gt;,LENGTH&lt;BR /&gt;,CYLINDERS&lt;BR /&gt;FROM CARS1&lt;BR /&gt;UNION ALL&lt;BR /&gt;SELECT&lt;BR /&gt;MAKE&lt;BR /&gt;,MSRP&lt;BR /&gt;,HORSEPOWER&lt;BR /&gt;,ORIGIN&lt;BR /&gt;,TYPE&lt;BR /&gt;,WEIGHT&lt;BR /&gt;FROM CARS2&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Column 4 from the first contributor of UNION ALL is not the same type as its counterpart from the second.&lt;BR /&gt;ERROR: Column 5 from the first contributor of UNION ALL is not the same type as its counterpart from the second.&lt;/P&gt;&lt;P&gt;I want to use Proc SQL only&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Kajal&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 06:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537320#M147765</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2019-02-21T06:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: SQL UNION operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537321#M147766</link>
      <description>&lt;P&gt;Maxim 14: Use the Right Tool, and that is a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars3;
set
  cars1
  cars2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not using it borders on insanity.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 06:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537321#M147766</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-21T06:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: SQL UNION operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537324#M147767</link>
      <description>&lt;P&gt;This works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE CARS1 AS SELECT
CYLINDERS ,MAKE ,MSRP ,HORSEPOWER ,INVOICE ,LENGTH 
FROM SASHELP.CARS
;
QUIT;
PROC SQL;
CREATE TABLE CARS2 AS SELECT
ORIGIN ,TYPE ,WEIGHT ,MAKE ,MSRP ,HORSEPOWER
FROM SASHELP.CARS
;
QUIT;

data cars3;
set cars1;
set cars2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let us know if it worked for you.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Feb 2019 06:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537324#M147767</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2019-02-21T06:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: SQL UNION operator</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537358#M147787</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has the correct solution (although mostly I would recommend proc append with the force option).&amp;nbsp; To continue using SQL for this you would need to expand both tables to have the same columns:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table cars3 as 
  select make
         ,msrp
         ,horsepower
         ,invoice
         ,length
         ,cylinders
         ,""
         ,""
         .
  from   cars1
  union all
  select make
         ,msrp
         ,horsepower
         ,""
         ,.
         ,.
         ,.
         ,origin
         ,type
         ,weight
  from   cars2;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Feb 2019 09:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-UNION-operator/m-p/537358#M147787</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-21T09:55:59Z</dc:date>
    </item>
  </channel>
</rss>

