<?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: FedSQL grouping error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872236#M344595</link>
    <description>&lt;P&gt;There is no aggregate MEDIAN() function in FEDSQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the MEDIAN of a single value is just that value using it that way in your query makes no sense. If you replace it with its equivalent&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;precisions as median_precision&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is clearer why FEDSQL is complaining.&amp;nbsp; Unlke PROC SQL in FEDSQL SAS will not automatically remerge aggregate results back onto all of the individual rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to calculate the median over the whole dataset then use PROC MEANS or PROC UNIVARIATE.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2023 13:13:20 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-04-26T13:13:20Z</dc:date>
    <item>
      <title>FedSQL grouping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872219#M344586</link>
      <description>&lt;P&gt;Hi people&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below is causing this error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR: Column "AAAA.PRECISIONS" must be GROUPed or used in an aggregate function&lt;BR /&gt;ERROR: The action stopped due to errors.&lt;BR /&gt;ERROR: The FedSQL action was not successful.&lt;/PRE&gt;&lt;P&gt;No idea what is generating the error in the final aggreagation, as all the sub-queries work fine (tested)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc fedsql sessref=casauto;

create table casuser.test as


select

mean(precisions) as mean_precision,
median(precisions) as median_precision

from

(

select 
aaa.person_id,
count(distinct(aaa.gms_deliverable_id))/5 as precisions


from 

(
select
a.person_id,
b.gms_deliverable_id

from
user_recc_open a

left join 
recc_test_open b

on a.person_id=b.person_id 
and inputn(a.gms_deliverable_id,'best.')=b.gms_deliverable_id
) aaa

group by aaa.person_id

) aaaa
;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2023 12:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872219#M344586</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2023-04-26T12:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: FedSQL grouping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872226#M344590</link>
      <description>&lt;P&gt;I add that If I just remove the median function from the code, the error disappear and the code works , which is weird cause the median function is listed as available function for fedsql&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_038/fedsqlref/n12fyogjg75fznn1dk3worxdalfs.htm" target="_blank" rel="noopener"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/v_038/fedsqlref/n12fyogjg75fznn1dk3worxdalfs.htm&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;median(precisions) as median_precision&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2023 12:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872226#M344590</guid>
      <dc:creator>dcortell</dc:creator>
      <dc:date>2023-04-26T12:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: FedSQL grouping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872234#M344593</link>
      <description>&lt;P&gt;Median() is "row function" i.e. it works on multiple variables, e.g. median(a.x,a.y,a.z) and returns medin of x, y, and z.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mean() is "row function" too.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code works wit Mean() because Mean() is alias for AVG() and AVG() as "column function".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two different pages in doc:&lt;/P&gt;
&lt;P&gt;AVG:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_038/fedsqlref/p0914cxk53dlurn1lmnfevdiekm2.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/v_038/fedsqlref/p0914cxk53dlurn1lmnfevdiekm2.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;MEAN:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_038/fedsqlref/p1gtv0q63ascpcn139jw8tpnvbjw.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/v_038/fedsqlref/p1gtv0q63ascpcn139jw8tpnvbjw.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 12:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872234#M344593</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-26T12:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: FedSQL grouping error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872236#M344595</link>
      <description>&lt;P&gt;There is no aggregate MEDIAN() function in FEDSQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the MEDIAN of a single value is just that value using it that way in your query makes no sense. If you replace it with its equivalent&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;precisions as median_precision&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is clearer why FEDSQL is complaining.&amp;nbsp; Unlke PROC SQL in FEDSQL SAS will not automatically remerge aggregate results back onto all of the individual rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to calculate the median over the whole dataset then use PROC MEANS or PROC UNIVARIATE.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 13:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FedSQL-grouping-error/m-p/872236#M344595</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-26T13:13:20Z</dc:date>
    </item>
  </channel>
</rss>

