<?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 Getting Duplicate rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739522#M230829</link>
    <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting duplicate rows in data. The result is correct but it's generating same rows multiple times.&lt;/P&gt;&lt;P&gt;The code is :&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table final as&lt;/P&gt;&lt;P&gt;select month_year , count(distinct ccsid) as unique_visitor&lt;/P&gt;&lt;P&gt;from login_old&lt;/P&gt;&lt;P&gt;where ccsid ne '&amp;nbsp; '&amp;nbsp;&lt;/P&gt;&lt;P&gt;group by month_year;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting result as below :&lt;/P&gt;&lt;P&gt;2020-04-01&amp;nbsp; &amp;nbsp; 12989&lt;/P&gt;&lt;P&gt;2020-04-01&amp;nbsp; &amp;nbsp; 12989&lt;/P&gt;&lt;P&gt;2020-04-01&amp;nbsp; &amp;nbsp; 12989&lt;/P&gt;&lt;P&gt;2020-04-01&amp;nbsp; &amp;nbsp; 12989&lt;/P&gt;&lt;P&gt;2020-05-01&amp;nbsp; &amp;nbsp; 17894&lt;/P&gt;&lt;P&gt;2020-05-01&amp;nbsp; &amp;nbsp; 17894&lt;/P&gt;&lt;P&gt;2020-05-01&amp;nbsp; &amp;nbsp; 17894&lt;/P&gt;&lt;P&gt;2020-05-01&amp;nbsp; &amp;nbsp; 17894&lt;/P&gt;&lt;P&gt;I want only one row for each result. Duplication is not needed.&lt;/P&gt;</description>
    <pubDate>Thu, 06 May 2021 15:31:27 GMT</pubDate>
    <dc:creator>anandmgjsa</dc:creator>
    <dc:date>2021-05-06T15:31:27Z</dc:date>
    <item>
      <title>Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739522#M230829</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting duplicate rows in data. The result is correct but it's generating same rows multiple times.&lt;/P&gt;&lt;P&gt;The code is :&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table final as&lt;/P&gt;&lt;P&gt;select month_year , count(distinct ccsid) as unique_visitor&lt;/P&gt;&lt;P&gt;from login_old&lt;/P&gt;&lt;P&gt;where ccsid ne '&amp;nbsp; '&amp;nbsp;&lt;/P&gt;&lt;P&gt;group by month_year;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting result as below :&lt;/P&gt;&lt;P&gt;2020-04-01&amp;nbsp; &amp;nbsp; 12989&lt;/P&gt;&lt;P&gt;2020-04-01&amp;nbsp; &amp;nbsp; 12989&lt;/P&gt;&lt;P&gt;2020-04-01&amp;nbsp; &amp;nbsp; 12989&lt;/P&gt;&lt;P&gt;2020-04-01&amp;nbsp; &amp;nbsp; 12989&lt;/P&gt;&lt;P&gt;2020-05-01&amp;nbsp; &amp;nbsp; 17894&lt;/P&gt;&lt;P&gt;2020-05-01&amp;nbsp; &amp;nbsp; 17894&lt;/P&gt;&lt;P&gt;2020-05-01&amp;nbsp; &amp;nbsp; 17894&lt;/P&gt;&lt;P&gt;2020-05-01&amp;nbsp; &amp;nbsp; 17894&lt;/P&gt;&lt;P&gt;I want only one row for each result. Duplication is not needed.&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 15:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739522#M230829</guid>
      <dc:creator>anandmgjsa</dc:creator>
      <dc:date>2021-05-06T15:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739528#M230832</link>
      <description>Check if month_year has a format on it and that's likely causing the issue. You're seeing the dates as the same but they're not really.&lt;BR /&gt;You usually don't see that with the day component though, but it's the only reason I can think of for SQL to behave this way. SQL aggregation does not honour SAS formats. You need to apply the format instead.&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;create table final as&lt;BR /&gt;&lt;BR /&gt;select put(t1.month_year, yymmn6.) as month_year , count(distinct ccsid) as unique_visitor&lt;BR /&gt;&lt;BR /&gt;from login_old t1&lt;BR /&gt;&lt;BR /&gt;where ccsid ne '  ' &lt;BR /&gt;&lt;BR /&gt;group by put(t1.month_year, yymmn6.);&lt;BR /&gt;&lt;BR /&gt;quit;</description>
      <pubDate>Thu, 06 May 2021 15:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739528#M230832</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-06T15:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739548#M230841</link>
      <description>It's throwing error&lt;BR /&gt;error : Numeric format YYMMN in put function requires a numeric argument.</description>
      <pubDate>Thu, 06 May 2021 16:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739548#M230841</guid>
      <dc:creator>anandmgjsa</dc:creator>
      <dc:date>2021-05-06T16:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739564#M230847</link>
      <description>What's the type of your month_year variable?&lt;BR /&gt;</description>
      <pubDate>Thu, 06 May 2021 17:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739564#M230847</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-06T17:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739586#M230859</link>
      <description>This is character.</description>
      <pubDate>Thu, 06 May 2021 17:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739586#M230859</guid>
      <dc:creator>anandmgjsa</dc:creator>
      <dc:date>2021-05-06T17:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739591#M230863</link>
      <description>Then that shouldn't be happening. To confirm, this is your full query and your data is exactly as shown? I would expect this for example if you had other columns included or an * somewhere but I don't see that. So it seems like SQL isn't considering your values to be the same group for some reason. It could be you have invisible characters on the date field somehow messing it up.</description>
      <pubDate>Thu, 06 May 2021 18:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739591#M230863</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-06T18:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739766#M230941</link>
      <description>Add 'distinct' keyword.&lt;BR /&gt;&lt;BR /&gt;select  DISTINCT month_year , count(distinct ccsid) as unique_visitor</description>
      <pubDate>Fri, 07 May 2021 13:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739766#M230941</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-07T13:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739778#M230948</link>
      <description>&lt;P&gt;Check the field&amp;nbsp;&lt;SPAN&gt;month_year&amp;nbsp;for leading spaces. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or invisible characters like TAB ('09'x) CR ('0D'x) LF ('0A'x) non-breaking space ('A0'x) null ('00'x)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or some of the hyphens are not hyphens but other character like en-dash or em-dash.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 14:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739778#M230948</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-07T14:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Duplicate rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739784#M230949</link>
      <description>&lt;P&gt;You sure you didn't include some third variable in the SELECT list of variables?&lt;/P&gt;
&lt;P&gt;If you include non-grouping and non-aggregate values then SAS will remerge the aggregate values back on the results.&lt;/P&gt;
&lt;P&gt;SAS will include a note in the log:&lt;/P&gt;
&lt;PRE&gt;1512  proc sql;
1513  select sex, mean(age) as mean_age, height
1514  from sashelp.class
1515  group by sex
1516  ;
NOTE: The query requires remerging summary statistics back with the original data.&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 May 2021 14:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-Duplicate-rows/m-p/739784#M230949</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-07T14:36:24Z</dc:date>
    </item>
  </channel>
</rss>

