<?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 PROC SQL SELECT DISTINCT vs GROUP BY in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT-DISTINCT-vs-GROUP-BY/m-p/465828#M285262</link>
    <description>&lt;P&gt;Anybody have some good resources on using select distinct vs group by? I feel hesitant when using them and find myself confused as to which one to use or if there are times you need to use both.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;</description>
    <pubDate>Tue, 29 May 2018 20:53:14 GMT</pubDate>
    <dc:creator>pchappus</dc:creator>
    <dc:date>2018-05-29T20:53:14Z</dc:date>
    <item>
      <title>PROC SQL SELECT DISTINCT vs GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT-DISTINCT-vs-GROUP-BY/m-p/465828#M285262</link>
      <description>&lt;P&gt;Anybody have some good resources on using select distinct vs group by? I feel hesitant when using them and find myself confused as to which one to use or if there are times you need to use both.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 20:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT-DISTINCT-vs-GROUP-BY/m-p/465828#M285262</guid>
      <dc:creator>pchappus</dc:creator>
      <dc:date>2018-05-29T20:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT DISTINCT vs GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT-DISTINCT-vs-GROUP-BY/m-p/465839#M285263</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212034"&gt;@pchappus&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Run below and examine the results. May be that explains things to you already a bit more.&lt;/P&gt;
&lt;P&gt;In a nutshell: You use DISTINCT to de-duplicate rows, you use GROUP BY to aggregate values by the variables in the group by statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input groupvar nvar cvar $;
  datalines;
1 10 A
1 10 A
1 20 B
2 50 B
2 40 B
;
run;

proc sql;
  select distinct groupvar, nvar, cvar
  from have
  ;
  select groupvar, sum(nvar) as sum_nvar, cvar
  from have
  group by groupvar
  ;
  select distinct groupvar, sum(nvar) as sum_nvar, cvar
  from have
  group by groupvar
  ;

  select distinct groupvar, sum(nvar) as sum_nvar, cvar
  from have
  group by groupvar
  having sum(nvar)&amp;gt;80
  ;

quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 21:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT-DISTINCT-vs-GROUP-BY/m-p/465839#M285263</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-05-29T21:29:25Z</dc:date>
    </item>
  </channel>
</rss>

