<?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 Error with Summary functions are restricted tot he SELECT and HAVING clauses in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854873#M337880</link>
    <description>&lt;P&gt;I am taking a Udemy class for preparation for the Advanced SAS Programmer certificate. I've never used PROC SQL before and working my way thru the class material using a copy of some useful data from work. I am running SAS V9.4 but have an older set of the Base SAS Procedures Guide (V9.1.3).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Source:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
	title  'Sum of defined cylinders by volume emulation type';
	select  Unit_Cap_Cyl,
			count(Unit_Cap_Cyl) as 	Qty_Vols			label='# Volumes'	,
			sum(Unit_Cap_Cyl) 	as 	Sum_Unit_Cap_Cyl	label='# Cylinders'

	from	Work.DSPL_TBL
	group by Sum_Unit_Cap_Cyl;	
	quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I comment out the 'group by Sum_Unit_Cap_Cyl' statement and put the semicolon after the from statement I will get a table with the correct data but not sorted.&lt;/P&gt;
&lt;P&gt;If I use the group by statement I get the 'Summary functions are restricted to the SELECT and HAVING clauses only' error. The error shows up after the group by statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm looking at the example code on Page-1149 of the Base SAS V9.1.3 Procedures Guide (volume-3) and I think functionally my code should match the example there.&lt;/P&gt;
&lt;P&gt;Once I have this piece working I will want to produce only one line for each unique value of the Unit_Cap_Cyl variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many previously submitted questions out here with the same error but I'm not seeing an answer that seems to fit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Jan 2023 17:12:34 GMT</pubDate>
    <dc:creator>lchristensen</dc:creator>
    <dc:date>2023-01-20T17:12:34Z</dc:date>
    <item>
      <title>Proc SQL Error with Summary functions are restricted tot he SELECT and HAVING clauses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854873#M337880</link>
      <description>&lt;P&gt;I am taking a Udemy class for preparation for the Advanced SAS Programmer certificate. I've never used PROC SQL before and working my way thru the class material using a copy of some useful data from work. I am running SAS V9.4 but have an older set of the Base SAS Procedures Guide (V9.1.3).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Source:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
	title  'Sum of defined cylinders by volume emulation type';
	select  Unit_Cap_Cyl,
			count(Unit_Cap_Cyl) as 	Qty_Vols			label='# Volumes'	,
			sum(Unit_Cap_Cyl) 	as 	Sum_Unit_Cap_Cyl	label='# Cylinders'

	from	Work.DSPL_TBL
	group by Sum_Unit_Cap_Cyl;	
	quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I comment out the 'group by Sum_Unit_Cap_Cyl' statement and put the semicolon after the from statement I will get a table with the correct data but not sorted.&lt;/P&gt;
&lt;P&gt;If I use the group by statement I get the 'Summary functions are restricted to the SELECT and HAVING clauses only' error. The error shows up after the group by statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm looking at the example code on Page-1149 of the Base SAS V9.1.3 Procedures Guide (volume-3) and I think functionally my code should match the example there.&lt;/P&gt;
&lt;P&gt;Once I have this piece working I will want to produce only one line for each unique value of the Unit_Cap_Cyl variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many previously submitted questions out here with the same error but I'm not seeing an answer that seems to fit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 17:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854873#M337880</guid>
      <dc:creator>lchristensen</dc:creator>
      <dc:date>2023-01-20T17:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Error with Summary functions are restricted tot he SELECT and HAVING clauses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854875#M337882</link>
      <description>&lt;P&gt;In PROC SQL you need to tell the Group By that you are using a calculated column. And I think you want ORDER BY for sorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
	title  'Sum of defined cylinders by volume emulation type';
	select  Unit_Cap_Cyl,
			count(Unit_Cap_Cyl) as 	Qty_Vols			label='# Volumes'	,
			sum(Unit_Cap_Cyl) 	as 	Sum_Unit_Cap_Cyl	label='# Cylinders'

	from	Work.DSPL_TBL
	order by (calculated Sum_Unit_Cap_Cyl);	
	quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All of the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0w2pkrm208upln11i9r4ogwyvow.htm" target="_self"&gt;most recent SAS documentation is available for free&lt;/A&gt;&amp;nbsp;online.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check out this &lt;A href="https://www.youtube.com/watch?v=afICXE5iZYo" target="_self"&gt;recent tutorial that covers this topic here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 17:19:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854875#M337882</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2023-01-20T17:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Error with Summary functions are restricted tot he SELECT and HAVING clauses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854911#M337906</link>
      <description>&lt;P&gt;Thank you but the Group By value (Unit_Cap_Cyl) is not a calculated value.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 21:06:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854911#M337906</guid>
      <dc:creator>lchristensen</dc:creator>
      <dc:date>2023-01-20T21:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Error with Summary functions are restricted tot he SELECT and HAVING clauses</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854915#M337910</link>
      <description>&lt;P&gt;I got it to work.&lt;/P&gt;
&lt;P&gt;The GROUP BY Unit_Cap_Cyl needed&amp;nbsp; &amp;nbsp;'having Unit_Cap_Cyl GE 0'&amp;nbsp; &amp;nbsp; &amp;nbsp;which also got rid of a lot of missing values.&lt;/P&gt;
&lt;PRE&gt;Proc SQL;
	title  'Sum of defined cylinders by volume emulation type';
	select  Unit_Cap_Cyl,
			count(Unit_Cap_Cyl) as 	Qty_Vols			label='# Volumes'	,
			sum(Unit_Cap_Cyl) 	as 	Sum_Unit_Cap_Cyl	label='# Cylinders'
	from	Work.DSPL_TBL
		GROUP BY Unit_Cap_Cyl	having Unit_Cap_Cyl GE 0
		order by Unit_Cap_Cyl;
	quit;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;TABLE class="systitleandfootercontainer" border="0" summary="Page Layout" width="100%" frame="void" rules="none" cellspacing="1" cellpadding="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="c systemtitle"&gt;Sum of defined cylinders by volume emulation type&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Unit_Cap_Cyl&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;&amp;nbsp;Volumes&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;&amp;nbsp;Cylinders&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2107&lt;/TD&gt;
&lt;TD class="r data"&gt;32&lt;/TD&gt;
&lt;TD class="r data"&gt;67424&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3339&lt;/TD&gt;
&lt;TD class="r data"&gt;576&lt;/TD&gt;
&lt;TD class="r data"&gt;1923264&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;5800&lt;/TD&gt;
&lt;TD class="r data"&gt;256&lt;/TD&gt;
&lt;TD class="r data"&gt;1484800&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;10017&lt;/TD&gt;
&lt;TD class="r data"&gt;2688&lt;/TD&gt;
&lt;TD class="r data"&gt;26925696&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;32760&lt;/TD&gt;
&lt;TD class="r data"&gt;160&lt;/TD&gt;
&lt;TD class="r data"&gt;5241600&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;65520&lt;/TD&gt;
&lt;TD class="r data"&gt;5561&lt;/TD&gt;
&lt;TD class="r data"&gt;3.6436E8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;262668&lt;/TD&gt;
&lt;TD class="r data"&gt;80&lt;/TD&gt;
&lt;TD class="r data"&gt;21013440&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;263781&lt;/TD&gt;
&lt;TD class="r data"&gt;768&lt;/TD&gt;
&lt;TD class="r data"&gt;2.0258E8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 20 Jan 2023 21:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-with-Summary-functions-are-restricted-tot-he/m-p/854915#M337910</guid>
      <dc:creator>lchristensen</dc:creator>
      <dc:date>2023-01-20T21:22:08Z</dc:date>
    </item>
  </channel>
</rss>

