<?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 Proc SQL Case Statement Error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616203#M180370</link>
    <description>&lt;P&gt;Hello Beautiful People!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I keep running into a syntax error when for my last Case Statement (Case MOB), but I do not know why it's wrong.&amp;nbsp; Below is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table MOB&amp;amp;YYMM. as 
select * from
	(select
		YYMM,
		MOB,
		count(a.PROD_ACCT_NO) as AcctCt,
		sum(STMT) as BalAmt,
		avg(STMT) as AVG_Bal_Amt,
		Year,
		substr(put(&amp;amp;YYMM.,4.),3,2) as Month_Var,
			Case calculated Month_Var
				when '01' then 'Jan'
				when '02' then 'Feb'
				when '03' then 'Mar'
				when '04' then 'Apr'
				when '05' then 'May'
				when '06' then 'Jun'
				when '07' then 'Jul'
				when '08' then 'Aug'
				when '09' then 'Sep'
				when '10' then 'Oct'
				when '11' then 'Nov'
				when '12' then 'Dec'
			End as Month,

			Case MOB
				when &amp;lt;13 then '1-12'
				when &amp;gt;=13 and &amp;lt;61 then '13-60'
				when &amp;gt;=61 and &amp;lt;121 then '61-120'
				when &amp;gt;=121 then '121+'
			End as MOB_Range
from example3 as a
group by MOB
);
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The log gives the following error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, 
              a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER. &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My end goal is to try to use this case statement to create ranges for my MOB variable.&amp;nbsp; The MOB variable is an integer, and I would like the ranges to be strings.&amp;nbsp; Any information on this is greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Valentine&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jan 2020 14:19:04 GMT</pubDate>
    <dc:creator>davidvalentine</dc:creator>
    <dc:date>2020-01-09T14:19:04Z</dc:date>
    <item>
      <title>Proc SQL Case Statement Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616203#M180370</link>
      <description>&lt;P&gt;Hello Beautiful People!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I keep running into a syntax error when for my last Case Statement (Case MOB), but I do not know why it's wrong.&amp;nbsp; Below is the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table MOB&amp;amp;YYMM. as 
select * from
	(select
		YYMM,
		MOB,
		count(a.PROD_ACCT_NO) as AcctCt,
		sum(STMT) as BalAmt,
		avg(STMT) as AVG_Bal_Amt,
		Year,
		substr(put(&amp;amp;YYMM.,4.),3,2) as Month_Var,
			Case calculated Month_Var
				when '01' then 'Jan'
				when '02' then 'Feb'
				when '03' then 'Mar'
				when '04' then 'Apr'
				when '05' then 'May'
				when '06' then 'Jun'
				when '07' then 'Jul'
				when '08' then 'Aug'
				when '09' then 'Sep'
				when '10' then 'Oct'
				when '11' then 'Nov'
				when '12' then 'Dec'
			End as Month,

			Case MOB
				when &amp;lt;13 then '1-12'
				when &amp;gt;=13 and &amp;lt;61 then '13-60'
				when &amp;gt;=61 and &amp;lt;121 then '61-120'
				when &amp;gt;=121 then '121+'
			End as MOB_Range
from example3 as a
group by MOB
);
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The log gives the following error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, 
              a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER. &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My end goal is to try to use this case statement to create ranges for my MOB variable.&amp;nbsp; The MOB variable is an integer, and I would like the ranges to be strings.&amp;nbsp; Any information on this is greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Valentine&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 14:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616203#M180370</guid>
      <dc:creator>davidvalentine</dc:creator>
      <dc:date>2020-01-09T14:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Case Statement Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616206#M180371</link>
      <description>&lt;P&gt;You can only use single values or complete conditions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;			Case
				when MOB &amp;lt; 13 then '1-12'
				when MOB &amp;gt;= 13 and MOB &amp;lt; 61 then '13-60'
				when MOB &amp;gt;= 61 and MOB &amp;lt; 121 then '61-120'
				when MOB &amp;gt;= 121 then '121+'
			End as MOB_Range
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jan 2020 14:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616206#M180371</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-09T14:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Case Statement Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616211#M180372</link>
      <description>&lt;P&gt;Just a suggestion to clean up your query. Instead of the case statement for the month_var, take the date and apply something like MONYY format and then extract the first 3 characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
dt = '31MAR2019'd;
mon_var=put(put(dt,monyy.),$3.);
put _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jan 2020 14:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616211#M180372</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-01-09T14:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Case Statement Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616217#M180376</link>
      <description>&lt;P&gt;Straight forward and to the point; thanks, KurtBremser.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 14:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Case-Statement-Error/m-p/616217#M180376</guid>
      <dc:creator>davidvalentine</dc:creator>
      <dc:date>2020-01-09T14:43:31Z</dc:date>
    </item>
  </channel>
</rss>

