<?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: SQL to identify the duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870346#M343770</link>
    <description>That's good. Any hint how to handle this query in external databases like&lt;BR /&gt;Snowflake?&lt;BR /&gt;</description>
    <pubDate>Tue, 18 Apr 2023 13:04:29 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2023-04-18T13:04:29Z</dc:date>
    <item>
      <title>SQL to identify the duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870321#M343760</link>
      <description>&lt;P&gt;I've the table as shown below. If I ignore the 'Serial_Num' field then there are few duplicate records. Now I want to identify the 'Serial_Num' of those duplicate records. Any help to achieve this using SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="335"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="79"&gt;Serial_Num&lt;/TD&gt;
&lt;TD width="64"&gt;Name&lt;/TD&gt;
&lt;TD width="64"&gt;Age&lt;/TD&gt;
&lt;TD width="64"&gt;Salary&lt;/TD&gt;
&lt;TD width="64"&gt;Gender&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;David&lt;/TD&gt;
&lt;TD&gt;34&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;David&lt;/TD&gt;
&lt;TD&gt;34&lt;/TD&gt;
&lt;TD&gt;1000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Y&gt;
&lt;TR&gt;
&lt;TD width="79"&gt;Serial_Num&lt;/TD&gt;
&lt;TD width="64"&gt;Name&lt;/TD&gt;
&lt;TD width="64"&gt;Age&lt;/TD&gt;
&lt;TD width="64"&gt;Salary&lt;/TD&gt;
&lt;TD width="64"&gt;Gender&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;David&lt;/TD&gt;
&lt;TD&gt;34&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;David&lt;/TD&gt;
&lt;TD&gt;34&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;David&lt;/TD&gt;
&lt;TD&gt;34&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;Deepak&lt;/TD&gt;
&lt;TD&gt;24&lt;/TD&gt;
&lt;TD&gt;200&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;Deepak&lt;/TD&gt;
&lt;TD&gt;24&lt;/TD&gt;
&lt;TD&gt;200&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 10:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870321#M343760</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-04-18T10:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: SQL to identify the duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870324#M343762</link>
      <description>&lt;P&gt;You can use group by and having clause in proc sql.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table output_table as select * from input_table
group by Name, Age, Salary, Gender having count(*)&amp;gt;=2;
quit;
proc print data=output_table;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2023 10:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870324#M343762</guid>
      <dc:creator>MayurJadhav</dc:creator>
      <dc:date>2023-04-18T10:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: SQL to identify the duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870330#M343765</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430243"&gt;@MayurJadhav&lt;/a&gt;&amp;nbsp; I've got the error&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;values "Serial_Num' in select clause is neither an aggregate nor in the group by clause&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2023 12:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870330#M343765</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-04-18T12:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL to identify the duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870338#M343766</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430243"&gt;@MayurJadhav&lt;/a&gt;&amp;nbsp; I've got the error&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;values "Serial_Num' in select clause is neither an aggregate nor in the group by clause&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you using PROC SQL?&amp;nbsp; Or are you running the SQL code in some foreign database?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show the SAS log for the query that is failing.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 12:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870338#M343766</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-18T12:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: SQL to identify the duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870339#M343767</link>
      <description>Yes, I have executed the query in Snowflake.&lt;BR /&gt;&lt;BR /&gt;I believe that we will get the similar error if we execute the similar&lt;BR /&gt;query in SAS.&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Apr 2023 12:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870339#M343767</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-04-18T12:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: SQL to identify the duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870345#M343769</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes, I have executed the query in Snowflake.&lt;BR /&gt;&lt;BR /&gt;I believe that we will get the similar error if we execute the similar&lt;BR /&gt;query in SAS.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, you won't. You'll get a NOTE about the automatic remerge, which is the purpose of the suggested code.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 12:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870345#M343769</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-18T12:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: SQL to identify the duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870346#M343770</link>
      <description>That's good. Any hint how to handle this query in external databases like&lt;BR /&gt;Snowflake?&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Apr 2023 13:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870346#M343770</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-04-18T13:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: SQL to identify the duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870350#M343771</link>
      <description>&lt;P&gt;Something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table output_table as
  select t1.* 
  from input_table as t1
  inner join (
    select Name, Age, Salary, Gender
    from input_table
    group by Name, Age, Salary, Gender
    having count(*) &amp;gt;= 2
  ) as t2
  on t1.name = t2.name and t1.age = t2.age and t1.salary = t2.salary and t1.gender = t2.gender&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2023 13:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-to-identify-the-duplicates/m-p/870350#M343771</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-18T13:13:07Z</dc:date>
    </item>
  </channel>
</rss>

