<?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 Max(date) having clause in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Max-date-having-clause/m-p/812008#M40644</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;I am querying the latest events of two companies in their latest events from the code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table WORK.MEETING_EVENTS as select * from connection to MYCONNECTION
(select
COMPANY_A,
COMPANY_A_ID,
EVENT_NAME,
COMPANY_B,
COMPANY_B_ID,
EVENT_ID,
EVENT_DT
FROM &amp;amp;MEETING_EVENTS_YEARLY.
WHERE UPPER(EVENT_NAME) IN ('SCHOOL HOLIDAY','ANNIVERSARY','NEW YEAR EVE','CHRISTMAS')
GROUP BY COMPANY_A,COMPANY_B
HAVING EVENT_DT = MAX(EVENT_DT)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I already added the group by clause but I still get the error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Error: CLI description error: [SAS][ODBC SQL Server Wire Protocol Driver][Microsoft SQL Server]Column 'MEETING_EVENTS_YEARLY.EVENT_DT'
Invalid in HAVING clause because it is not included in aggregate function or GROUP BY clause. :
[SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Unable to parse batch due to compilation error.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly help.&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
    <pubDate>Sun, 08 May 2022 16:57:45 GMT</pubDate>
    <dc:creator>sarahzhou</dc:creator>
    <dc:date>2022-05-08T16:57:45Z</dc:date>
    <item>
      <title>Max(date) having clause</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Max-date-having-clause/m-p/812008#M40644</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I am querying the latest events of two companies in their latest events from the code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table WORK.MEETING_EVENTS as select * from connection to MYCONNECTION
(select
COMPANY_A,
COMPANY_A_ID,
EVENT_NAME,
COMPANY_B,
COMPANY_B_ID,
EVENT_ID,
EVENT_DT
FROM &amp;amp;MEETING_EVENTS_YEARLY.
WHERE UPPER(EVENT_NAME) IN ('SCHOOL HOLIDAY','ANNIVERSARY','NEW YEAR EVE','CHRISTMAS')
GROUP BY COMPANY_A,COMPANY_B
HAVING EVENT_DT = MAX(EVENT_DT)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I already added the group by clause but I still get the error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Error: CLI description error: [SAS][ODBC SQL Server Wire Protocol Driver][Microsoft SQL Server]Column 'MEETING_EVENTS_YEARLY.EVENT_DT'
Invalid in HAVING clause because it is not included in aggregate function or GROUP BY clause. :
[SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Unable to parse batch due to compilation error.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly help.&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sun, 08 May 2022 16:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Max-date-having-clause/m-p/812008#M40644</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-05-08T16:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Max(date) having clause</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Max-date-having-clause/m-p/812027#M40645</link>
      <description>&lt;P&gt;I guess SQL Server doesn't do auto-remerge like SAS SQL does. You will just have to do the merge yourself. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table WORK.MEETING_EVENTS as 
select * from connection to MYCONNECTION
(select
a.COMPANY_A,
a.COMPANY_A_ID,
a.EVENT_NAME,
a.COMPANY_B,
a.COMPANY_B_ID,
a.EVENT_ID,
a.EVENT_DT
FROM &amp;amp;MEETING_EVENTS_YEARLY. as a inner join
(	select 
		COMPANY_A, 
		COMPANY_B, 
		MAX(EVENT_DT) as select_dt
	from &amp;amp;MEETING_EVENTS_YEARLY.
	WHERE UPPER(EVENT_NAME) IN ('SCHOOL HOLIDAY','ANNIVERSARY','NEW YEAR EVE','CHRISTMAS')
	GROUP BY COMPANY_A, COMPANY_B  ) as b
on a.COMPANY_A=b.COMPANY_A and a.COMPANY_B=b.COMPANY_B and a.EVENT_DT=b.select_dt
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 May 2022 18:43:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Max-date-having-clause/m-p/812027#M40645</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-05-08T18:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: Max(date) having clause</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Max-date-having-clause/m-p/812059#M40646</link>
      <description>&lt;P&gt;Awesome,thanks, it works!&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 03:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Max-date-having-clause/m-p/812059#M40646</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-05-09T03:04:13Z</dc:date>
    </item>
  </channel>
</rss>

