<?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 FEDSQL vs SQL Grouping in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/FEDSQL-vs-SQL-Grouping/m-p/439730#M69147</link>
    <description>&lt;P&gt;SQL works as intended&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table ds as select * from sdtm.ds&lt;BR /&gt;where dscat='DISP EVENT'&lt;BR /&gt;group by usubjid&lt;BR /&gt;having visitnum=max(visitnum)&lt;BR /&gt;order by usubjid, visitnum;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FEDSQL gives ERROR: Column "DS.STUDYID" must be GROUPed or used in an aggregate function&lt;/P&gt;&lt;P&gt;It seems as if the FEDSQL requires all the selected variables to be grouped, but then it doesn't take the latest visit.&lt;/P&gt;&lt;P&gt;Is there a way to replicate the SQL code with FEDSQL?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc fedsql;&lt;BR /&gt;create table ds3 as select * from sdtm.ds&lt;BR /&gt;where dscat='DISP EVENT'&lt;BR /&gt;group by usubjid&lt;BR /&gt;having visitnum=max(visitnum)&lt;BR /&gt;order by usubjid, visitnum;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Feb 2018 15:25:14 GMT</pubDate>
    <dc:creator>MatthewWiedel</dc:creator>
    <dc:date>2018-02-23T15:25:14Z</dc:date>
    <item>
      <title>FEDSQL vs SQL Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/FEDSQL-vs-SQL-Grouping/m-p/439730#M69147</link>
      <description>&lt;P&gt;SQL works as intended&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table ds as select * from sdtm.ds&lt;BR /&gt;where dscat='DISP EVENT'&lt;BR /&gt;group by usubjid&lt;BR /&gt;having visitnum=max(visitnum)&lt;BR /&gt;order by usubjid, visitnum;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FEDSQL gives ERROR: Column "DS.STUDYID" must be GROUPed or used in an aggregate function&lt;/P&gt;&lt;P&gt;It seems as if the FEDSQL requires all the selected variables to be grouped, but then it doesn't take the latest visit.&lt;/P&gt;&lt;P&gt;Is there a way to replicate the SQL code with FEDSQL?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc fedsql;&lt;BR /&gt;create table ds3 as select * from sdtm.ds&lt;BR /&gt;where dscat='DISP EVENT'&lt;BR /&gt;group by usubjid&lt;BR /&gt;having visitnum=max(visitnum)&lt;BR /&gt;order by usubjid, visitnum;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 15:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/FEDSQL-vs-SQL-Grouping/m-p/439730#M69147</guid>
      <dc:creator>MatthewWiedel</dc:creator>
      <dc:date>2018-02-23T15:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: FEDSQL vs SQL Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/FEDSQL-vs-SQL-Grouping/m-p/439742#M69148</link>
      <description>&lt;P&gt;This remerging with original data that PROC SQL does, is not ANSI standard. Which it seems that FedSQL is following at least in this case.&lt;BR /&gt;In later implementations of SQL this kind of functionality is handled in &lt;EM&gt;window functions&lt;/EM&gt;. They, however to my knowledge, is not implemented (yet) in FedSQL.&lt;BR /&gt;So the alternative would be to do the grouping in an in-line view and join with the original data.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2018 12:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/FEDSQL-vs-SQL-Grouping/m-p/439742#M69148</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-02-26T12:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: FEDSQL vs SQL Grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/FEDSQL-vs-SQL-Grouping/m-p/439751#M69150</link>
      <description>&lt;P&gt;Thank you for the information;&amp;nbsp; I used your suggestion and looked up an ANSI solution.&amp;nbsp; Here it is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc fedsql;&lt;BR /&gt;create table ds3 as select a.*&lt;BR /&gt;from sdtm.ds a,&lt;BR /&gt;(select max(visitnum) as maxvis, usubjid from sdtm.ds group by usubjid) b&lt;BR /&gt;where a.usubjid=b.usubjid and&lt;BR /&gt;a.visitnum=b.maxvis and&lt;BR /&gt;a.dscat='DISP EVENT'&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 16:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/FEDSQL-vs-SQL-Grouping/m-p/439751#M69150</guid>
      <dc:creator>MatthewWiedel</dc:creator>
      <dc:date>2018-02-23T16:26:18Z</dc:date>
    </item>
  </channel>
</rss>

