<?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 UNION in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400307#M97048</link>
    <description>&lt;P&gt;By default an &lt;A href="https://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n0vo2lglyrnexwn14emi8m0jqvrj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n05ape0l2g4a37n1mq4w24mjm5li" target="_self"&gt;SQL UNION only selects distinct values&lt;/A&gt;. If you want duplicates (i.e all rows from both tables) you need a UNION ALL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example from doc:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   title 'A UNION ALL B';
   select * from sql.a
   union all
   select * from sql.b;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 12 Sep 2018 18:11:51 GMT</pubDate>
    <dc:creator>ChrisBrooks</dc:creator>
    <dc:date>2018-09-12T18:11:51Z</dc:date>
    <item>
      <title>PROC SQL UNION - unique vs with duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400297#M97044</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two tables A and B, both with the same columns:&lt;/P&gt;
&lt;PRE&gt;Z1 character7
Z2 character2
Z3 numeric8
Z4 Numeric8
Z5 character200
Z6 numeric8&lt;/PRE&gt;
&lt;P&gt;In A there are 1 121 776 rows&lt;/P&gt;
&lt;P&gt;In B there are 114 028 rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do this in a PROC SQL:&lt;/P&gt;
&lt;PRE&gt;		CREATE TABLE &amp;amp;output_table. AS
			SELECT * FROM A
			UNION SELECT * FROM B;&lt;/PRE&gt;
&lt;P&gt;My output table has... 333 456 rows...&lt;/P&gt;
&lt;P&gt;Can someone explain me how it is possible???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks by advance&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400297#M97044</guid>
      <dc:creator>FP12</dc:creator>
      <dc:date>2018-09-12T18:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400307#M97048</link>
      <description>&lt;P&gt;By default an &lt;A href="https://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n0vo2lglyrnexwn14emi8m0jqvrj.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n05ape0l2g4a37n1mq4w24mjm5li" target="_self"&gt;SQL UNION only selects distinct values&lt;/A&gt;. If you want duplicates (i.e all rows from both tables) you need a UNION ALL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example from doc:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   title 'A UNION ALL B';
   select * from sql.a
   union all
   select * from sql.b;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Sep 2018 18:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400307#M97048</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2018-09-12T18:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400308#M97049</link>
      <description>&lt;P&gt;You have duplicates in both data sets.&amp;nbsp; The example below produces one observation even though A has 3 and B has 2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a b;
  length z1 $7 z2 $2 z3 z4 8 z5 $200 z6 8;
z1='1234567';
z2='12';
z3=1;
z4=2;
z5=repeat('abcde',40);
z6=3;

output a;output a; output a;
output b;output b;
run;

proc sql;
CREATE TABLE _table AS
			SELECT * FROM A
			UNION SELECT * FROM B;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Oct 2017 15:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400308#M97049</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-02T15:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400326#M97053</link>
      <description>&lt;P&gt;UNION doesn't insert duplicate rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNION ALL does insert duplicate rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 class="xis-title"&gt;UNION&lt;/H3&gt;
&lt;DIV id="n1p29jumivkuaxn1olwkzhlypy34" class="xis-topicContent"&gt;
&lt;DIV id="n1gxek42i0cot5n1wpfir93txx0c" class="xis-paragraph"&gt;The UNION operator produces a table that contains &lt;STRONG&gt;all the unique rows&lt;/STRONG&gt; that result from both table expressions&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 02 Oct 2017 16:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400326#M97053</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-02T16:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400631#M97132</link>
      <description>&lt;P&gt;Or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data &amp;amp;output_table;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set a b;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which may run faster than the SQL.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 15:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-unique-vs-with-duplicates/m-p/400631#M97132</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-03T15:59:26Z</dc:date>
    </item>
  </channel>
</rss>

