<?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: SQL case when else in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939088#M368780</link>
    <description>&lt;P&gt;EDIT: Too many cases and elses here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;28 proc sql;
29 create table temp as
30 select contract_number, sum(enrollment) as parent_enrol,
31 case when (calculated parent_enrol lt 50000) then 1
32 &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;else&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;case&lt;/STRONG&gt;&lt;/FONT&gt; when parent_enrol le 200000 then 2
33 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;else&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;case&lt;/FONT&gt;&lt;/STRONG&gt; when (calculated parent_enrol gt 200000) then 3
34 else 4
35 end as parent_size&lt;/PRE&gt;
&lt;P&gt;Correct syntax&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;28 proc sql;
29 create table temp as
30 select contract_number, sum(enrollment) as parent_enrol,
31 case when (calculated parent_enrol lt 50000) then 1
32   when parent_enrol le 200000 then 2
33  when (calculated parent_enrol gt 200000) then 3
34 else 4
35 end as parent_size&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9248"&gt;@Batman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Not sure why this isn't working, shouldn't I have "end" in the location of the error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;28 proc sql;&lt;BR /&gt;29 create table temp as&lt;BR /&gt;30 select contract_number, sum(enrollment) as parent_enrol,&lt;BR /&gt;31 case when (calculated parent_enrol lt 50000) then 1&lt;BR /&gt;32 else case when parent_enrol le 200000 then 2&lt;BR /&gt;33 else case when (calculated parent_enrol gt 200000) then 3&lt;BR /&gt;34 else 4&lt;BR /&gt;35 end as parent_size&lt;BR /&gt;__&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&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, END, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~,&lt;BR /&gt;~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;36 from D107342.AP15747022_Master&lt;BR /&gt;37 group by contract_number;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;38 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2024 16:14:26 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2024-08-13T16:14:26Z</dc:date>
    <item>
      <title>SQL case when else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939086#M368779</link>
      <description>&lt;P&gt;Not sure why this isn't working, shouldn't I have "end" in the location of the error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;28 proc sql;&lt;BR /&gt;29 create table temp as&lt;BR /&gt;30 select contract_number, sum(enrollment) as parent_enrol,&lt;BR /&gt;31 case when (calculated parent_enrol lt 50000) then 1&lt;BR /&gt;32 else case when parent_enrol le 200000 then 2&lt;BR /&gt;33 else case when (calculated parent_enrol gt 200000) then 3&lt;BR /&gt;34 else 4&lt;BR /&gt;35 end as parent_size&lt;BR /&gt;__&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&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, END, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~,&lt;BR /&gt;~=.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;36 from D107342.AP15747022_Master&lt;BR /&gt;37 group by contract_number;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;38 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 15:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939086#M368779</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2024-08-13T15:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: SQL case when else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939088#M368780</link>
      <description>&lt;P&gt;EDIT: Too many cases and elses here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;28 proc sql;
29 create table temp as
30 select contract_number, sum(enrollment) as parent_enrol,
31 case when (calculated parent_enrol lt 50000) then 1
32 &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;else&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;case&lt;/STRONG&gt;&lt;/FONT&gt; when parent_enrol le 200000 then 2
33 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;else&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;case&lt;/FONT&gt;&lt;/STRONG&gt; when (calculated parent_enrol gt 200000) then 3
34 else 4
35 end as parent_size&lt;/PRE&gt;
&lt;P&gt;Correct syntax&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;28 proc sql;
29 create table temp as
30 select contract_number, sum(enrollment) as parent_enrol,
31 case when (calculated parent_enrol lt 50000) then 1
32   when parent_enrol le 200000 then 2
33  when (calculated parent_enrol gt 200000) then 3
34 else 4
35 end as parent_size&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9248"&gt;@Batman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Not sure why this isn't working, shouldn't I have "end" in the location of the error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;28 proc sql;&lt;BR /&gt;29 create table temp as&lt;BR /&gt;30 select contract_number, sum(enrollment) as parent_enrol,&lt;BR /&gt;31 case when (calculated parent_enrol lt 50000) then 1&lt;BR /&gt;32 else case when parent_enrol le 200000 then 2&lt;BR /&gt;33 else case when (calculated parent_enrol gt 200000) then 3&lt;BR /&gt;34 else 4&lt;BR /&gt;35 end as parent_size&lt;BR /&gt;__&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&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, END, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~,&lt;BR /&gt;~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;36 from D107342.AP15747022_Master&lt;BR /&gt;37 group by contract_number;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;38 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 16:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939088#M368780</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-08-13T16:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: SQL case when else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939090#M368782</link>
      <description>&lt;P&gt;Still getting an error even with your modification&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;27 proc sql;&lt;BR /&gt;28 create table temp as&lt;BR /&gt;29 select contract_number, sum(enrollment) as parent_enrol,&lt;BR /&gt;30 case when calculated parent_enrol lt 50000 then 1&lt;BR /&gt;31 else when calculated parent_enrol le 200000 then 2&lt;BR /&gt;__________&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&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, END, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~,&lt;BR /&gt;~=.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;32 else when calculated parent_enrol gt 200000 then 3&lt;BR /&gt;33 else 4&lt;BR /&gt;34 end as parent_size&lt;BR /&gt;35 from D107342.AP15747022_Master&lt;BR /&gt;36 group by contract_number;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;37 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 16:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939090#M368782</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2024-08-13T16:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: SQL case when else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939091#M368783</link>
      <description>No ELSE as well except on last one.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0a85s0ijz65irn1h3jtariooea5.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0a85s0ijz65irn1h3jtariooea5.htm&lt;/A&gt;</description>
      <pubDate>Tue, 13 Aug 2024 16:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-case-when-else/m-p/939091#M368783</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-08-13T16:03:19Z</dc:date>
    </item>
  </channel>
</rss>

