<?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 ALL is deleting duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906038#M357805</link>
    <description>&lt;P&gt;I found the issue. Apparently you can have a "SET" or "MULTISET" table in Teradata.&lt;SPAN&gt; A table defined as SET table doesn't store the duplicate records, whereas the MULTISET table&amp;nbsp;&lt;/SPAN&gt;can store duplicate records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So I changed the table to MULTISET and now it is solved.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for your help&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2023 15:33:55 GMT</pubDate>
    <dc:creator>user34567</dc:creator>
    <dc:date>2023-12-04T15:33:55Z</dc:date>
    <item>
      <title>PROC SQL UNION ALL is deleting duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906009#M357793</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using the query below to combine three tables but in the output table the duplicates are deleted. Not sure why since I did use an UNION ALL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;UREN_2021 and UREN_2022 are a direct copy of UREN_2023 since I'm still testing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;SELECT * FROM "Table"."UREN_2021"&lt;/DIV&gt;&lt;DIV&gt;UNION ALL&lt;/DIV&gt;&lt;DIV&gt;SELECT * FROM "Table"."UREN_2022"&lt;/DIV&gt;&lt;DIV&gt;UNION ALL&lt;/DIV&gt;&lt;DIV&gt;SELECT * FROM "Table"."UREN_2023"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Does someone know what is causing this issue?&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Dec 2023 14:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906009#M357793</guid>
      <dc:creator>user34567</dc:creator>
      <dc:date>2023-12-04T14:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION ALL is deleting duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906010#M357794</link>
      <description>&lt;P&gt;What does the log say?&lt;BR /&gt;As a reminder we don't what your data is.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 14:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906010#M357794</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-12-04T14:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION ALL is deleting duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906012#M357795</link>
      <description>&lt;P&gt;Are you querying some foreign database?&amp;nbsp; Show the LOG for the full step.&lt;/P&gt;
&lt;P&gt;Because it works fine with plain old SAS datasets.&lt;/P&gt;
&lt;PRE&gt;710  proc sql ;
711  create table want as
712  select * from sashelp.class
713  union all
714  select * from sashelp.class
715  ;
NOTE: Table WORK.WANT created, with 38 rows and 5 columns.

716  quit;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Dec 2023 14:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906012#M357795</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-04T14:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION ALL is deleting duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906027#M357802</link>
      <description>&lt;P&gt;Yes I'm connecting to Teradata. This is the full script:&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PROC SQL;&lt;/DIV&gt;&lt;DIV&gt;CONNECT TO teradata AS td (&amp;amp;teradata_connect_string.);&lt;/DIV&gt;&lt;DIV&gt;EXECUTE&lt;/DIV&gt;&lt;DIV&gt;(&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;INSERT INTO "Table"."UREN"&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; columnA,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnB,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnC,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnD,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnE,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnF,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnG,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnH,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnI,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnJ,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; columnK)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;SELECT * FROM "Table"."UREN_2021"&lt;/DIV&gt;&lt;DIV&gt;UNION ALL&lt;/DIV&gt;&lt;DIV&gt;SELECT * FROM "Table"."UREN_2022"&lt;/DIV&gt;&lt;DIV&gt;UNION ALL&lt;/DIV&gt;&lt;DIV&gt;SELECT * FROM "Table"."UREN_2023"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;) BY td;&lt;/DIV&gt;&lt;DIV&gt;QUIT:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The LOG:&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=""&gt;27         PROC SQL;
28         CONNECT TO teradata AS td
SYMBOLGEN:  Macro variable TERADATA_CONNECT_STRING resolves to SERVER="td" AUTHDOMAIN=TeradataAuth  TPT=yes SQL_FUNCTIONS=all 
            CONNECTION=global BULKLOAD=yes mode=teradata
28       !                           (&amp;amp;teradata_connect_string.);
NOTE:  Credential obtained from SAS metadata server.
29         
30         EXECUTE
31         (
32         	
33          INSERT INTO "Table"."UREN"
34         	(
35             columnA,
36             columnB,
37             columnC,
38             columnD,
39             columnE,
40             columnF,
41             columnG,
42             columnH,
43             columnI,
44             columnJ,
45             columnK)
46         
47         SELECT * FROM "TABLE"."UREN_2021"
48         
49         UNION ALL
2                                                          The SAS System                      Monday, December  4, 2023 08:22:00 AM

50         
51         SELECT * FROM "TABLE"."UREN_2022"
52         
53         UNION ALL
54         
55         SELECT * FROM "TABLE"."UREN_2023"
56         
57         ) BY td;
 
TERADATA_629: Executed: on connection 0
INSERT INTO "Table"."UREN" ( columnA, columnB, columnC, columnD, columnE, columnF, columnG, 
columnH, columnI, columnJ, columnK) SELECT * FROM "Table"."UREN_2021" UNION ALL SELECT * FROM 
"Table"."UREN_2022" UNION ALL SELECT * FROM "Table"."UREN_2023"
 
TERADATA: 2032 row(s) inserted/updated/deleted.
 
Summary Statistics for TERADATA are:
Total SQL execution seconds were:                   0.095859
Total seconds used by the TERADATA ACCESS engine were     0.096102
 
58         QUIT:
59         
60         %LET _CLIENTTASKLABEL=;
61         %LET _CLIENTPROCESSFLOWNAME=;
62         %LET _CLIENTPROJECTPATH=;
63         %LET _CLIENTPROJECTPATHHOST=;
64         %LET _CLIENTPROJECTNAME=;
65         %LET _SASPROGRAMFILE=;
66         %LET _SASPROGRAMFILEHOST=;
67         
68         ;*';*";*/;quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.11 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              380.43k
      OS Memory           54408.00k
      Timestamp           12/04/2023 03:53:21 PM
      Step Count                        326  Switch Count  18
      Page Faults                       0
      Page Reclaims                     29
      Page Swaps                        0
      Voluntary Context Switches        131
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

68       !                run;
69         ODS _ALL_ CLOSE;
70         
71         
72         QUIT; RUN;
73         &lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;In the log you can see that 2032 rows were inserted. I Expected 2032*3 = 6096 rows to be inserted since the tables are identical.&lt;/DIV&gt;&lt;DIV&gt;Also when I run an UNION ALL in Teradata directly, I do get a count of 6096 rows.&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Dec 2023 15:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906027#M357802</guid>
      <dc:creator>user34567</dc:creator>
      <dc:date>2023-12-04T15:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION ALL is deleting duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906030#M357803</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/445848"&gt;@user34567&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;You want to insert the result set of the union all into the table UREN.&lt;BR /&gt;Ensure that all the statements of the union all&amp;nbsp; return the same number of columns i.e, the column you want to insert. Sample insert statement is given below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;insert into Result_table (A,B) 
select A, B from Table1
union all
select A, B from Table2
union all
select A, B from Table3&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 15:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906030#M357803</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2023-12-04T15:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION ALL is deleting duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906038#M357805</link>
      <description>&lt;P&gt;I found the issue. Apparently you can have a "SET" or "MULTISET" table in Teradata.&lt;SPAN&gt; A table defined as SET table doesn't store the duplicate records, whereas the MULTISET table&amp;nbsp;&lt;/SPAN&gt;can store duplicate records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So I changed the table to MULTISET and now it is solved.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for your help&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 15:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906038#M357805</guid>
      <dc:creator>user34567</dc:creator>
      <dc:date>2023-12-04T15:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL UNION ALL is deleting duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906114#M357816</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/445848"&gt;@user34567&lt;/a&gt;&amp;nbsp;- Please update your post as answered in that case.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 20:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-UNION-ALL-is-deleting-duplicates/m-p/906114#M357816</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-12-04T20:23:25Z</dc:date>
    </item>
  </channel>
</rss>

