<?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: Fun with PROC SQL Summary Functions in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517324#M3312</link>
    <description>The one to one statement is an assumption, though it's likely correct &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I think GROUP BY is faster than Distinct.&lt;BR /&gt;&lt;BR /&gt;I was coming to say that I thought you should have gotten the answer actually, your answer actually shows how to do it correctly, mine does not!</description>
    <pubDate>Fri, 30 Nov 2018 01:36:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-11-30T01:36:40Z</dc:date>
    <item>
      <title>Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517304#M3306</link>
      <description>&lt;P&gt;This is my first time using PROC SQL.&amp;nbsp; My task is to identify the average, min, and max salary by department.&amp;nbsp; I have successfully calculated the stats, but cannot seem to figure out how to present each department uniquely.&amp;nbsp;&amp;nbsp; I have no errors on my log.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc sql.JPG" style="width: 476px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25274i57BE5980DDFCC2B8/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc sql.JPG" alt="proc sql.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table salinfo as
select 
Dept_ID,
Dept_Name,
mean (Salary) as AverageSalary format=comma12.,
min(Salary) as MinSalary format=comma12.,
max(Salary) as MaxSalary format=comma12.
from work.combine;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 00:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517304#M3306</guid>
      <dc:creator>AMMAN</dc:creator>
      <dc:date>2018-11-30T00:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517315#M3307</link>
      <description>&lt;P&gt;GROUP BY is what you need to add.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 00:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517315#M3307</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2018-11-30T00:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517316#M3308</link>
      <description>&lt;P&gt;I get the same result.&amp;nbsp; It orders them by department name, but lists all the rows.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 00:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517316#M3308</guid>
      <dc:creator>AMMAN</dc:creator>
      <dc:date>2018-11-30T00:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517318#M3309</link>
      <description>&lt;P&gt;You ran the code below and got the same results?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table salinfo as
select 
Dept_ID,
Dept_Name,
mean (Salary) as AverageSalary format=comma12.,
min(Salary) as MinSalary format=comma12.,
max(Salary) as MaxSalary format=comma12.
from work.combine
group by Dept_ID,
               Dept_Name;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Nov 2018 01:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517318#M3309</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2018-11-30T01:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517320#M3310</link>
      <description>&lt;P&gt;You have a misunderstanding about how a SQL query works.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you select a variable that is not summarized, ie a group variable it has to be in the GROUP clause.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In most RDBMS it will generate an error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS, it will return all rows with the average duplicated for each row.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want it grouped, you need to make sure any variables that are not aggregated are in the GROUP clause.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table salinfo as
select 
&lt;FONT color="#800080"&gt;&lt;STRONG&gt;Dept_ID,
Dept_Name, /*both need to be in group otherwise you get each row*/&lt;/STRONG&gt;&lt;/FONT&gt;
mean (Salary) as AverageSalary format=comma12.,
min(Salary) as MinSalary format=comma12.,
max(Salary) as MaxSalary format=comma12.
from work.combine;
quit;&lt;/PRE&gt;
&lt;P&gt;Summary Tasks also work well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/221595"&gt;@AMMAN&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is my first time using PROC SQL.&amp;nbsp; My task is to identify the average, min, and max salary by department.&amp;nbsp; I have successfully calculated the stats, but cannot seem to figure out how to present each department uniquely.&amp;nbsp;&amp;nbsp; I have no errors on my log.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc sql.JPG" style="width: 476px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25274i57BE5980DDFCC2B8/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc sql.JPG" alt="proc sql.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table salinfo as
select 
Dept_ID,
Dept_Name,
mean (Salary) as AverageSalary format=comma12.,
min(Salary) as MinSalary format=comma12.,
max(Salary) as MaxSalary format=comma12.
from work.combine;
quit;&lt;/CODE&gt;&lt;/PRE&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>Fri, 30 Nov 2018 01:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517320#M3310</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-30T01:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517321#M3311</link>
      <description>&lt;P&gt;That's a much better and more detailed explanation...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It isn't 100% true, though. In this case, since department ID and department have a one-to-one relationship, you could just have one in the group by but add a "distinct" to the select clause.&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 salinfo as
select distinct 
Dept_ID,
Dept_Name,
mean (Salary) as AverageSalary format=comma12.,
min(Salary) as MinSalary format=comma12.,
max(Salary) as MaxSalary format=comma12.
from work.combine
group by dept_id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Nov 2018 01:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517321#M3311</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2018-11-30T01:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517324#M3312</link>
      <description>The one to one statement is an assumption, though it's likely correct &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I think GROUP BY is faster than Distinct.&lt;BR /&gt;&lt;BR /&gt;I was coming to say that I thought you should have gotten the answer actually, your answer actually shows how to do it correctly, mine does not!</description>
      <pubDate>Fri, 30 Nov 2018 01:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517324#M3312</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-30T01:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517326#M3313</link>
      <description>&lt;P&gt;Assumption based on the data he provided, but I agree it's better to not assume the one-to-one. I think I'll be okay without getting credit. I'll cry a bit, but I'll recover.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 01:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517326#M3313</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2018-11-30T01:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Fun with PROC SQL Summary Functions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517585#M3351</link>
      <description>&lt;P&gt;Thank you both very much for the input.&amp;nbsp;&amp;nbsp; The assumption is true, in this case, there is a 1-to-1 relationship.&amp;nbsp; However, I know how to do it in cases where it is not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't realize that indicating a post as the resolution gave credit.&amp;nbsp; I am happy to revise it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AMMAN&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 17:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fun-with-PROC-SQL-Summary-Functions/m-p/517585#M3351</guid>
      <dc:creator>AMMAN</dc:creator>
      <dc:date>2018-11-30T17:24:27Z</dc:date>
    </item>
  </channel>
</rss>

