<?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 How to KEEP duplicates in Proc SQL, aggregating for quarter in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-KEEP-duplicates-in-Proc-SQL-aggregating-for-quarter/m-p/669093#M23195</link>
    <description>&lt;P&gt;I am trying to aggregate data for the quarter from months.&lt;/P&gt;&lt;P&gt;Data is quite simple has Type, Code and then values (revenue, quantity, label etc.).&lt;/P&gt;&lt;P&gt;Occasionally some lines&amp;nbsp; in month 1 match exactly lines in month 2 or month 3 of the quarter. I just discovered that in that case data from one of the month is dropped ( i.e. duplicates are eliminated). I need to keep all data! Can this be done with proc sql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current program in the nutshell:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table Q as&lt;/P&gt;&lt;P&gt;select type, code, sum (revenue) as Revenue, sum(quantity) as Quantity, label&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&lt;/P&gt;&lt;P&gt;(select * from month1&amp;nbsp; union&lt;/P&gt;&lt;P&gt;&amp;nbsp;select * from month2 union&lt;/P&gt;&lt;P&gt;select&amp;nbsp; * from month3)&lt;/P&gt;&lt;P&gt;where code is not null&lt;/P&gt;&lt;P&gt;group by type, code, label,&lt;/P&gt;&lt;P&gt;order by type , code;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jul 2020 06:01:10 GMT</pubDate>
    <dc:creator>User12321</dc:creator>
    <dc:date>2020-07-14T06:01:10Z</dc:date>
    <item>
      <title>How to KEEP duplicates in Proc SQL, aggregating for quarter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-KEEP-duplicates-in-Proc-SQL-aggregating-for-quarter/m-p/669093#M23195</link>
      <description>&lt;P&gt;I am trying to aggregate data for the quarter from months.&lt;/P&gt;&lt;P&gt;Data is quite simple has Type, Code and then values (revenue, quantity, label etc.).&lt;/P&gt;&lt;P&gt;Occasionally some lines&amp;nbsp; in month 1 match exactly lines in month 2 or month 3 of the quarter. I just discovered that in that case data from one of the month is dropped ( i.e. duplicates are eliminated). I need to keep all data! Can this be done with proc sql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current program in the nutshell:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table Q as&lt;/P&gt;&lt;P&gt;select type, code, sum (revenue) as Revenue, sum(quantity) as Quantity, label&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&lt;/P&gt;&lt;P&gt;(select * from month1&amp;nbsp; union&lt;/P&gt;&lt;P&gt;&amp;nbsp;select * from month2 union&lt;/P&gt;&lt;P&gt;select&amp;nbsp; * from month3)&lt;/P&gt;&lt;P&gt;where code is not null&lt;/P&gt;&lt;P&gt;group by type, code, label,&lt;/P&gt;&lt;P&gt;order by type , code;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 06:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-KEEP-duplicates-in-Proc-SQL-aggregating-for-quarter/m-p/669093#M23195</guid>
      <dc:creator>User12321</dc:creator>
      <dc:date>2020-07-14T06:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to KEEP duplicates in Proc SQL, aggregating for quarter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-KEEP-duplicates-in-Proc-SQL-aggregating-for-quarter/m-p/669103#M23196</link>
      <description>&lt;P&gt;You have to use UNION ALL to keep duplicates; unless you want to explicitly remove duplicates, it is always recommended to use UNION ALL, because it needs one less sort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your issue can also be solved with these two steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp / view=temp;
set
  month1
  month2
  month3
;
keep type code revenue quantity label;
where code ne " "; /* use . if code is numeric */
run;

proc summary data=temp nway;
class type code label;
var revenue quantity;
output
  out=want (drop=_type_ _freq_)
  sum()=
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jul 2020 07:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-KEEP-duplicates-in-Proc-SQL-aggregating-for-quarter/m-p/669103#M23196</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-14T07:07:11Z</dc:date>
    </item>
  </channel>
</rss>

