<?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: PROC SQL: CASE WHEN statement ERROR in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670079#M79192</link>
    <description>&lt;P&gt;Aside from the spurious blanks, you should create a format with ranges; your CASE clause might miss values with imprecisions caused by binary calculation.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jul 2020 08:20:58 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-07-17T08:20:58Z</dc:date>
    <item>
      <title>PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670026#M79190</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hoping someone can help... trying to execute a Case When statement but I keep receiving this error message:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&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;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Below is the PROC SQL code and attached is the data - I have no idea what I am missing &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thank you !!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE BUCKETS AS 
 
SELECT DISTINCT 
a.MONTH, 
a.YEAR, 
a.ANIMAL, 
a.BAN, 
a.VOLUME, 
a.SIGHTINGS,
(case 
when a. SIGHTINGS &amp;gt;= 0  and a. SIGHTINGS &amp;lt;=  49.99 then '1.0-49'   
when &amp;gt;= 50  a.SIGHTINGS &amp;lt;= 99.99 then '2.50-99'
when &amp;gt;= 100 a. SIGHTINGS &amp;lt;= 249.99 then '3.100-249'
when &amp;gt;= 250 a.SIGHTINGS &amp;lt;= 499.99 then '4.250-499'
when &amp;gt;= 500 a. SIGHTINGS &amp;lt;=999.99 then '5.500-999'
when a. SIGHTINGS &amp;gt;= 1000 then '6.1000+'
else '' end) as Buckets

FROM WORK.MERGE a
     
GROUP BY 
a.Month, 
a.YEAR, 
a.ANIMAL, 
a.BAN, 
a.VOLUME, 
a.SIGHTINGS

;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 00:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670026#M79190</guid>
      <dc:creator>sufiya</dc:creator>
      <dc:date>2020-07-17T00:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670032#M79191</link>
      <description>&lt;P&gt;Remove the spaces between "a." and "Sightings".&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 00:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670032#M79191</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-07-17T00:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670079#M79192</link>
      <description>&lt;P&gt;Aside from the spurious blanks, you should create a format with ranges; your CASE clause might miss values with imprecisions caused by binary calculation.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 08:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670079#M79192</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-17T08:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670099#M79194</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;, I did that and still getting the same error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 12:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670099#M79194</guid>
      <dc:creator>sufiya</dc:creator>
      <dc:date>2020-07-17T12:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670101#M79195</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191207"&gt;@sufiya&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;, I did that and still getting the same error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show us the log for this PROC SQL. Include the code as shown in the log, plus any NOTEs, ERRORs and WARNINGs. (For future reference, when code produces an error, you always need to show us the log as described, including the code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please click on the &amp;lt;/&amp;gt; icon and paste this part of the log into the window that appears. This will allow the SAS Community software to format the log properly and make it more readable.&amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Please do not skip this step.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 12:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670101#M79195</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-17T12:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670125#M79197</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&amp;nbsp; please see below for the full error message. Thank you,&lt;/P&gt;&lt;PRE&gt;36         (case
           _
           22
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, 
              CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  

37         when a. SIGHTINGS &amp;gt;= 0  and a. SIGHTINGS &amp;lt;=  49.99 then '1.0-49'   
           ____
           22
           76
ERROR 22-322: Syntax error, expecting one of the following: a name, (, ',', '.', ANSIMISS, AS, CROSS, FULL, INNER, JOIN, LEFT, 
              NATURAL, NOMISS, RIGHT.  

ERROR 76-322: Syntax error, statement will be ignored.

38         when &amp;gt;= 50  a.SIGHTINGS &amp;lt;= 99.99 then '2.50-99'
39         when &amp;gt;= 100 a. SIGHTINGS &amp;lt;= 249.99 then '3.100-249'
40         when &amp;gt;= 250 a.SIGHTINGS &amp;lt;= 499.99 then '4.250-499'
41         when &amp;gt;= 500 a. SIGHTINGS &amp;lt;=999.99 then '5.500-999'
42         when a. SIGHTINGS &amp;gt;= 1000 then '6.1000+'
43         else '' end) as Buckets
44&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 14:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670125#M79197</guid>
      <dc:creator>sufiya</dc:creator>
      <dc:date>2020-07-17T14:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670132#M79198</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191207"&gt;@sufiya&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&amp;nbsp; please see below for the full error message. Thank you,&lt;/P&gt;
&lt;PRE&gt;36         (case
           _
           22
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, 
              CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  

37         when a. SIGHTINGS &amp;gt;= 0  and a. SIGHTINGS &amp;lt;=  49.99 then '1.0-49'   
           ____
           22
           76
ERROR 22-322: Syntax error, expecting one of the following: a name, (, ',', '.', ANSIMISS, AS, CROSS, FULL, INNER, JOIN, LEFT, 
              NATURAL, NOMISS, RIGHT.  

ERROR 76-322: Syntax error, statement will be ignored.

38         when &amp;gt;= 50  a.SIGHTINGS &amp;lt;= 99.99 then '2.50-99'
39         when &amp;gt;= 100 a. SIGHTINGS &amp;lt;= 249.99 then '3.100-249'
40         when &amp;gt;= 250 a.SIGHTINGS &amp;lt;= 499.99 then '4.250-499'
41         when &amp;gt;= 500 a. SIGHTINGS &amp;lt;=999.99 then '5.500-999'
42         when a. SIGHTINGS &amp;gt;= 1000 then '6.1000+'
43         else '' end) as Buckets
44&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is NOT the complete Proc SQL code. Start with the Proc SQL statement and go to the Quit.&lt;/P&gt;
&lt;P&gt;The most likely thing is that you do not have a COMMA appearing before the CASE and/or should not start with ( . Everything on the select clause needs to be separated with a comma.&lt;/P&gt;
&lt;P&gt;That is why the diagnostic character _ appears under the ( character at the beginning of your case. That is the first position SAS found some problem. But it depends on what come before.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 14:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670132#M79198</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-17T14:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670136#M79199</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191207"&gt;@sufiya&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&amp;nbsp; please see below for the full error message. Thank you,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I want to see the COMPLETE LOG for PROC SQL, all of it, 100%, no exceptions, starting at the PROC SQL command, and then all the code, all the way down to the end of the PROC, and of course we need to see the ERROR, WARNING and NOTE messages, even if they are after the end of the PROC. Do not edit the LOG for PROC SQL in any way.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 15:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670136#M79199</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-17T15:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670162#M79202</link>
      <description>&lt;P&gt;When we give you advice, we expect you to FOLLOW it.&lt;/P&gt;
&lt;P&gt;The log shows clearly that you did NOT remove the blanks between the table alias and the variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DO THIS before you run the next test.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 16:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670162#M79202</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-17T16:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670164#M79203</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help guys! Figured it out, just needed to remove the 'Group By' + tweaked the CASEstatement and it ran with no errors.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE BUCKETS AS 
 
SELECT DISTINCT 
a.MONTH, 
a.YEAR, 
a.ANIMAL, 
a.BAN, 
a.VOLUME, 
a.SIGHTINGS,
(case  when a.SIGHTINGS &amp;gt;= 0  and a.SIGHTINGS &amp;lt;=  49.99 then '1.0-49'   
when a.SIGHTINGS  &amp;gt;= 50   and   a.SIGHTINGS &amp;lt;= 99.99 then '2.50-99'
when a.SIGHTINGS  &amp;gt;= 100 and   a.SIGHTINGS &amp;lt;= 249.99 then '3.100-249'
when a.SIGHTINGS  &amp;gt;= 250 and   a.SIGHTINGS &amp;lt;= 499.99 then '4.250-499'
when a.SIGHTINGS  &amp;gt;= 500 and   a.SIGHTINGS &amp;lt;=999.99 then '5.500-999'
when a. SIGHTINGS &amp;gt;= 1000 then '6.1000+'
else '' end) as Buckets

FROM WORK.MERGE a
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 17:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670164#M79203</guid>
      <dc:creator>sufiya</dc:creator>
      <dc:date>2020-07-17T17:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: CASE WHEN statement ERROR</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670170#M79204</link>
      <description>&lt;P&gt;You might investigate formats.&lt;/P&gt;
&lt;P&gt;You could create a format with the desired ranges and use that for almost any purpose that requires "binning" a single variable in analysis, reporting or graphing procedures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Formats have the flexibility of working with multiple variables with similar coding ranges, do not require adding variables if you want to change the ranges, or have multiple ranged defined simultaneously and use the desired one as situation demands and the logic for ranges in proc format often makes it much easier than if/then/else. And for specific procedures that support them, Tabulate, Report, Summary and Means, Multilabel formats allow overlapping ranges generating summaries for each defined range (which would require multiple variables otherwise).&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 17:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-CASE-WHEN-statement-ERROR/m-p/670170#M79204</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-17T17:19:01Z</dc:date>
    </item>
  </channel>
</rss>

