<?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 duplicate rows group by in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757876#M239254</link>
    <description>&lt;P&gt;I suspect &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; is right, date_new values are dates and you want to summarize by month. You must transform the daily dates into &lt;EM&gt;month dates&lt;/EM&gt; (e.g. the date of the first of the month) to calculate the counts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table disease2 as
select
	intnx("Month", date_new, 0) format=yymmn6. as month_new,
	count(*) as diseased
from disease1
group by calculated month_new;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note INTNX("Month", date_new, 0) returns the date of the first day of the month.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jul 2021 18:41:10 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2021-07-28T18:41:10Z</dc:date>
    <item>
      <title>Proc SQL duplicate rows group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757815#M239234</link>
      <description>&lt;P&gt;Feeling really frustrated this morning. Trying to do a very basic proc sql query and my output is not what I want it to be. Instead of having one row for each group, I am getting multiple rows with the same group. In my experience, this issue is a result of remerging - but I am not getting any errors in the log.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table disease2 as&lt;BR /&gt;select&lt;BR /&gt;date_new,&lt;BR /&gt;count(*) as diseased&lt;BR /&gt;from disease1&lt;BR /&gt;group by date_new&lt;BR /&gt;order by date_new;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;date_new diseased&amp;nbsp;&lt;/P&gt;&lt;P&gt;202012 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 2&lt;BR /&gt;202101 2&lt;BR /&gt;202102 2&lt;BR /&gt;202102 2&lt;BR /&gt;202102 1&lt;BR /&gt;202102 2&lt;BR /&gt;202102 2&lt;BR /&gt;202102 5&lt;BR /&gt;202102 4&lt;BR /&gt;202102 3&lt;BR /&gt;202102 6&lt;BR /&gt;202102 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;date_new diseased&amp;nbsp;&lt;/P&gt;&lt;P&gt;202012 1&lt;/P&gt;&lt;P&gt;202101 12&amp;nbsp;&lt;/P&gt;&lt;P&gt;202102&amp;nbsp; 29&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 17:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757815#M239234</guid>
      <dc:creator>Krysia24</dc:creator>
      <dc:date>2021-07-28T17:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL duplicate rows group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757818#M239237</link>
      <description>&lt;P&gt;date_new is likely formatted. &lt;BR /&gt;SAS SQL doesn't honour formats on your data. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table disease2 as
select
put(date_new, yymmn6.) as date_new,
count(*) as diseased
from disease1
group by put(date_new, yymmn6.)
order by calculated date_new;

QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or use PROC FREQ which does use formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=disease1 noprint;
table date_new / out=disease_counts_by_date nocum nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89165"&gt;@Krysia24&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Feeling really frustrated this morning. Trying to do a very basic proc sql query and my output is not what I want it to be. Instead of having one row for each group, I am getting multiple rows with the same group. In my experience, this issue is a result of remerging - but I am not getting any errors in the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table disease2 as&lt;BR /&gt;select&lt;BR /&gt;date_new,&lt;BR /&gt;count(*) as diseased&lt;BR /&gt;from disease1&lt;BR /&gt;group by date_new&lt;BR /&gt;order by date_new;&lt;/P&gt;
&lt;P&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My output:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date_new diseased&amp;nbsp;&lt;/P&gt;
&lt;P&gt;202012 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 1&lt;BR /&gt;202101 2&lt;BR /&gt;202101 2&lt;BR /&gt;202102 2&lt;BR /&gt;202102 2&lt;BR /&gt;202102 1&lt;BR /&gt;202102 2&lt;BR /&gt;202102 2&lt;BR /&gt;202102 5&lt;BR /&gt;202102 4&lt;BR /&gt;202102 3&lt;BR /&gt;202102 6&lt;BR /&gt;202102 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date_new diseased&amp;nbsp;&lt;/P&gt;
&lt;P&gt;202012 1&lt;/P&gt;
&lt;P&gt;202101 12&amp;nbsp;&lt;/P&gt;
&lt;P&gt;202102&amp;nbsp; 29&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 17:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757818#M239237</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-28T17:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL duplicate rows group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757876#M239254</link>
      <description>&lt;P&gt;I suspect &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; is right, date_new values are dates and you want to summarize by month. You must transform the daily dates into &lt;EM&gt;month dates&lt;/EM&gt; (e.g. the date of the first of the month) to calculate the counts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table disease2 as
select
	intnx("Month", date_new, 0) format=yymmn6. as month_new,
	count(*) as diseased
from disease1
group by calculated month_new;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note INTNX("Month", date_new, 0) returns the date of the first day of the month.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 18:41:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757876#M239254</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-07-28T18:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL duplicate rows group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757967#M239290</link>
      <description>&lt;P&gt;Thank you! I did not know formats were not honored in proc sql. Without an error or warning in the log, I was unsure what I did wrong. Thank you for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 00:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-duplicate-rows-group-by/m-p/757967#M239290</guid>
      <dc:creator>Krysia24</dc:creator>
      <dc:date>2021-07-29T00:19:52Z</dc:date>
    </item>
  </channel>
</rss>

