<?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: Having in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831241#M328461</link>
    <description>Thank you, Peter, but it doesn't work,beacause the result will be 08Sept2013 for IS_SUPPORT 137863.&lt;BR /&gt;In case whe I have the empty value, I need to choose the empty value and not the max.&lt;BR /&gt;</description>
    <pubDate>Wed, 31 Aug 2022 12:19:16 GMT</pubDate>
    <dc:creator>SASdevAnneMarie</dc:creator>
    <dc:date>2022-08-31T12:19:16Z</dc:date>
    <item>
      <title>Having in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831205#M328456</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the data RGA I have the multiple values of d_fin by is_support.&lt;/P&gt;
&lt;P&gt;d_fin is the date of creation, I need to choose the most recent or with the empty value.&lt;/P&gt;
&lt;P&gt;I try to use "having" but I have the syntax error :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, &lt;BR /&gt;CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you help me please ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Donnees as select  c.cd_rga, b.is_support, c.lb_court, b.d_fin,a.mt_ea,
		sum(a.mt_ea) as total	
	from SUPPORT as a
		left join RGA as b on a.is_support=b.is_support and (having b.d_fin=. or max(b.d_fin)=b.d_fin)
		left join RGPC as c on b.is_rga=c.is_rga
			where a.s_type_support="OK"
				group by c.cd_rga
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 09:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831205#M328456</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-08-31T09:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Having in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831231#M328457</link>
      <description>&lt;P&gt;This is untested since I can't see your data. But I think you want something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Donnees as 
   select  c.cd_rga
         , b.is_support
         , c.lb_court
         , b.d_fin
         , a.mt_ea,
	      , sum(a.mt_ea) as total	
	from SUPPORT as a

   left join (select is_support
              from RGA
              group by is_support
              having b.d_fin = . 
              or max(b.d_fin) = b.d_fin)  as b
   on a.is_support = b.is_support

	left join RGPC as c 
   on b.is_rga=c.is_rga

	where a.s_type_support="OK"
	group by c.cd_rga
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2022 10:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831231#M328457</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-31T10:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Having in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831232#M328458</link>
      <description>&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/sqlproc/p1n8ntmltj8ct6n1hso7x2ys6sbw.htm" target="_blank" rel="noopener"&gt;HAVING&lt;/A&gt; is a&amp;nbsp;&lt;U&gt;clause&lt;/U&gt; and can therefore not be part of a condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post usable (&lt;STRONG&gt;data steps with datalines&lt;/STRONG&gt;) examples for your datasets, and what you expect to get out of them with your query.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 10:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831232#M328458</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-31T10:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Having in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831235#M328459</link>
      <description>&lt;P&gt;Thank you Peter,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately it doesn't work in case when I have the empty vaue en non-empty value for the same IS_SUPPORT.&lt;/P&gt;
&lt;P&gt;In my case I need to tae the empty value. The code take the two values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASdevAnneMarie_0-1661945188460.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74896iBC21360A6E7F5B77/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASdevAnneMarie_0-1661945188460.png" alt="SASdevAnneMarie_0-1661945188460.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 11:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831235#M328459</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-08-31T11:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Having in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831237#M328460</link>
      <description>&lt;P&gt;Since you did not provide any sample data, I'm kind of shooting in the dark here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try changing the inner query to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct is_support
from RGA
group by is_support
having max(b.d_fin) = b.d_fin&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2022 11:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831237#M328460</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-31T11:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: Having in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831241#M328461</link>
      <description>Thank you, Peter, but it doesn't work,beacause the result will be 08Sept2013 for IS_SUPPORT 137863.&lt;BR /&gt;In case whe I have the empty value, I need to choose the empty value and not the max.&lt;BR /&gt;</description>
      <pubDate>Wed, 31 Aug 2022 12:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831241#M328461</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-08-31T12:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Having in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831253#M328466</link>
      <description>&lt;P&gt;I would like to use&amp;nbsp;max(b.d_fin) = b.d_fin and replace the empty value with&amp;nbsp;"31DEC2023"d but it doesn't work, I have the value 01/01/1960 and not 31/12/2023.&lt;/P&gt;
&lt;P&gt;Could you please explain me how to write the case statement ?&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 Donnees as 
   select  c.cd_rga
         , b.is_support
         , c.lb_court
         , b.d_fin
         , a.mt_ea,
	      , sum(a.mt_ea) as total	
	from SUPPORT as a

   left join (select is_support,
    case d_fin when . then d_fin="31DEC2023"d
             end as d_fin format ddmmyy10.
              from RGA
              group by is_support
              having 
              or max(b.d_fin) = b.d_fin)  as b
   on a.is_support = b.is_support

	left join RGPC as c 
   on b.is_rga=c.is_rga

	where a.s_type_support="OK"
	group by c.cd_rga
	;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 13:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831253#M328466</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-08-31T13:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Having in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831374#M328511</link>
      <description>&lt;P&gt;Thank you Peter !&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 09:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Having-in-proc-sql/m-p/831374#M328511</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2022-09-01T09:11:24Z</dc:date>
    </item>
  </channel>
</rss>

