<?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: Case When Statement and Null Value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477783#M286250</link>
    <description>IS NULL is valid syntax.&lt;BR /&gt;Perhaps it's new variable name that is the problem.&lt;BR /&gt;If you want to use names with spaces you have to use quotation and the n literal:&lt;BR /&gt;'Total Premium'n</description>
    <pubDate>Fri, 13 Jul 2018 05:52:10 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2018-07-13T05:52:10Z</dc:date>
    <item>
      <title>Case When Statement and Null Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477703#M286246</link>
      <description>&lt;P&gt;I am very new to SAS.&amp;nbsp; I am trying to create a Case When Statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* TOT_PREM */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;Case&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;When&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1.TOT_PREM &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;IS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NULL &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;Then&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;Else&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(Sum(t1.TOT_PREM)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;END&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Total Premium,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I am getting an error message ERROR22-322: Syntax error, expecting one of the following: !,!!,&amp;amp;,*,**,+,-,/,&amp;lt;,&amp;lt;=,&amp;lt;&amp;gt;,=,.,.,.=,?,AND,BETWEEN,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;What am I doing wrong?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 22:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477703#M286246</guid>
      <dc:creator>EKeimig</dc:creator>
      <dc:date>2018-07-12T22:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Case When Statement and Null Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477704#M286247</link>
      <description>&lt;P&gt;Try MISSING() instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS doesn't really have a concept of NULL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;when missing(t1.tot_prem) then 0
else ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220776"&gt;@EKeimig&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am very new to SAS.&amp;nbsp; I am trying to create a Case When Statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;/* TOT_PREM */&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;Case&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;When&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1.TOT_PREM &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;IS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NULL &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;Then&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;Else&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(Sum(t1.TOT_PREM)) &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;END&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;AS&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Total Premium,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I am getting an error message ERROR22-322: Syntax error, expecting one of the following: !,!!,&amp;amp;,*,**,+,-,/,&amp;lt;,&amp;lt;=,&amp;lt;&amp;gt;,=,.,.,.=,?,AND,BETWEEN,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;What am I doing wrong?&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 22:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477704#M286247</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-12T22:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Case When Statement and Null Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477706#M286248</link>
      <description>&lt;P&gt;This is the message I get now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;46 Case When Missing(t1.TOT_PREM) Then 0 Else&lt;/P&gt;&lt;P&gt;47 (Sum(t1.TOT_PREM)) END AS Total Premium,&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;_______&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;22&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;ERROR 22-322: Syntax error, expecting one of the following: ',', AS, FROM.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 22:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477706#M286248</guid>
      <dc:creator>EKeimig</dc:creator>
      <dc:date>2018-07-12T22:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Case When Statement and Null Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477708#M286249</link>
      <description>&lt;P&gt;You don't need to do that at all...SAS ignores missing values in the sum. If you were doing a mean this may be required, but it's not for a SUM().&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try SUM(t1.TOT_PREM) instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/220776"&gt;@EKeimig&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is the message I get now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;46 Case When Missing(t1.TOT_PREM) Then 0 Else&lt;/P&gt;
&lt;P&gt;47 (Sum(t1.TOT_PREM)) END AS Total Premium,&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;_______&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;22&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;ERROR 22-322: Syntax error, expecting one of the following: ',', AS, FROM.&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 22:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477708#M286249</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-12T22:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Case When Statement and Null Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477783#M286250</link>
      <description>IS NULL is valid syntax.&lt;BR /&gt;Perhaps it's new variable name that is the problem.&lt;BR /&gt;If you want to use names with spaces you have to use quotation and the n literal:&lt;BR /&gt;'Total Premium'n</description>
      <pubDate>Fri, 13 Jul 2018 05:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477783#M286250</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-07-13T05:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Case When Statement and Null Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477959#M286251</link>
      <description>&lt;P&gt;When you get an error copy the entire&amp;nbsp;procedure or data step code that generates the error from log including the error messages and paste into a code box opened using the forums {I} icon. This preserves the formatting of the error messages and the indicators that often show what SAS identified as the triggering error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And example:&lt;/P&gt;
&lt;PRE&gt;244  proc sql;
245     select case when sex='M' then 0
246            else 1 end as Total whatsit
                                   -------
                                   22
ERROR 22-322: Syntax error, expecting one of the following: ',', AS.

247     from sashelp.class;
248  quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

&lt;/PRE&gt;
&lt;P&gt;Notice that I am getting the same error: 22-322 with slightly different "expected" but the underscores show that "whatsit" is out of place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case if I wanted a variable "Total Whatsit" which has a space in the middle then I have to use the construct "Total whatsit"n to indicate a name literal that violates typical variable name rules. OR perhaps I thought there was another variable whatsit I wanted to select but just forgot to place the required comma between variables or expressions in SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you did not include the entire code from the log your specific error appears to be in a construct that allows more options than the example I showed but the basic principal applies: one of the expected characters or keywords needs to be before the underscored word &lt;STRONG&gt;or&lt;/STRONG&gt; you need to use a different variable name as the result of the case expression. I strongly suggest not using the name literal as the added quotes and required n following get tiresome.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 17:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/477959#M286251</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-13T17:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Case When Statement and Null Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/672158#M286252</link>
      <description>&lt;P&gt;I know this is old, but in case anyone else finds it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a few problems with the code here.&amp;nbsp; One is just extraneous parentheses, one is that there's "Total Premium" has a space in it...but the larger one is the logic of the CASE statement.&amp;nbsp; Remember that CASE looks at a single row and returns a result for each row, so you can't have a SUM *inside* your CASE statement.&amp;nbsp; The order must be reversed, like so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SUM(CASE WHEN t1.TOT_PREM IS NULL THEN 0 ELSE t1.TOT_PREM END) AS Total_Premium&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jul 2020 18:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-Statement-and-Null-Value/m-p/672158#M286252</guid>
      <dc:creator>Andy8</dc:creator>
      <dc:date>2020-07-24T18:53:37Z</dc:date>
    </item>
  </channel>
</rss>

