<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761033#M240746</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311117"&gt;@sasuser_sk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;PROC SQL NOEXEC;&lt;BR /&gt;SELECT (CASE&lt;BR /&gt;when(t1.SRVC_ID_3Mos is missing ) then t1.SRVC_ID_6Mos&lt;BR /&gt;else t1.SRVC_ID_6Mos&lt;BR /&gt;END) AS CALCULATION&lt;BR /&gt;FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try removing the parenthesis after "END".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, note, the code doesn't make sense to me.&amp;nbsp; Maybe I'm misunderstanding but it looks like that if the 3Mos value is missing the 6Mos value is used instead, but if it is not missing then the 6Mos value is also used.&amp;nbsp; Did you mean to use the 3Mos value if not missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like this, maybe?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL NOEXEC;
    SELECT (CASE
        when(t1.SRVC_ID_3Mos is missing ) then t1.SRVC_ID_6Mos
        else t1.SRVC_ID_&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;3Mos&lt;/FONT&gt;&lt;/STRONG&gt;
        END AS CALCULATION
    FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Wed, 11 Aug 2021 23:04:39 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-08-11T23:04:39Z</dc:date>
    <item>
      <title>CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761027#M240745</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am using case when In SAS EG with the code and error below. All fields are numeric and I don't understand what the problem is. Help would be appreciated. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL NOEXEC;&lt;BR /&gt;SELECT (CASE&lt;BR /&gt;when(t1.SRVC_ID_3Mos is missing ) then t1.SRVC_ID_6Mos&lt;BR /&gt;else t1.SRVC_ID_6Mos&lt;BR /&gt;END) AS CALCULATION&lt;BR /&gt;FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;&lt;BR /&gt;QUIT;&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;P&gt;;*';*";*/;quit;run;&lt;BR /&gt;2 OPTIONS PAGENO=MIN;&lt;BR /&gt;3 OPTION DEBUG=DBMS_SELECT SQL_IP_TRACE=(NOTE, SOURCE);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;4 PROC SQL NOEXEC;&lt;BR /&gt;5 SELECT (CASE&lt;BR /&gt;6 when(t1.SRVC_ID_3Mos is missing ) then t1.SRVC_ID_6Mos&lt;BR /&gt;7 &lt;BR /&gt;8 else t1.SRVC_ID_6Mos&lt;BR /&gt;9 END) AS CALCULATION&lt;BR /&gt;10 FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;11 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 0.00 seconds&lt;BR /&gt;&lt;BR /&gt;12 %PUT SQL_IPTRACE_RESULT=&amp;amp;SYS_SQL_IP_ALL;&lt;BR /&gt;SQL_IPTRACE_RESULT=-1&lt;BR /&gt;13 OPTIONS SQL_IP_TRACE=(NONE);&lt;BR /&gt;14 QUIT; RUN;&lt;BR /&gt;15&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 22:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761027#M240745</guid>
      <dc:creator>sasuser_sk</dc:creator>
      <dc:date>2021-08-11T22:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761033#M240746</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311117"&gt;@sasuser_sk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;PROC SQL NOEXEC;&lt;BR /&gt;SELECT (CASE&lt;BR /&gt;when(t1.SRVC_ID_3Mos is missing ) then t1.SRVC_ID_6Mos&lt;BR /&gt;else t1.SRVC_ID_6Mos&lt;BR /&gt;END) AS CALCULATION&lt;BR /&gt;FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try removing the parenthesis after "END".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, note, the code doesn't make sense to me.&amp;nbsp; Maybe I'm misunderstanding but it looks like that if the 3Mos value is missing the 6Mos value is used instead, but if it is not missing then the 6Mos value is also used.&amp;nbsp; Did you mean to use the 3Mos value if not missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like this, maybe?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL NOEXEC;
    SELECT (CASE
        when(t1.SRVC_ID_3Mos is missing ) then t1.SRVC_ID_6Mos
        else t1.SRVC_ID_&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;3Mos&lt;/FONT&gt;&lt;/STRONG&gt;
        END AS CALCULATION
    FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 23:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761033#M240746</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-11T23:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761039#M240748</link>
      <description>&lt;P&gt;It looks like&amp;nbsp;t1.SRVC_ID_3Mos and&amp;nbsp;t1.SRVC_ID_6Mos are different data types. You should check if that is the case.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 23:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761039#M240748</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-08-11T23:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761044#M240751</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;I believe needs also removal of the opening bracket before CASE&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 00:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761044#M240751</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-08-12T00:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761046#M240752</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;All fields are numeric&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;SAS doesn't seem to think so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, no need for brackets to write a CASE clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, use the coalesce() function here instead of CASE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 00:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761046#M240752</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-12T00:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761050#M240756</link>
      <description>PROC SQL NOEXEC;&lt;BR /&gt;SELECT CASE&lt;BR /&gt;when missing(t1.SRVC_ID_3Mos)  then t1.SRVC_ID_6Mos&lt;BR /&gt;else t1.SRVC_ID_6Mos&lt;BR /&gt;END AS New_Date&lt;BR /&gt;FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;&lt;BR /&gt;QUIT;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Aug 2021 01:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761050#M240756</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-12T01:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: CASE WHEN Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761089#M240775</link>
      <description>&lt;P&gt;Your code as posted works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data QUERY_FOR_AVG_3MONTHS_NONNULL;
SRVC_ID_3Mos = .;
SRVC_ID_6Mos = 1;
output;
SRVC_ID_3Mos = 1;
SRVC_ID_6Mos = 1;
output;
run;

PROC SQL NOEXEC;
SELECT (CASE
when(t1.SRVC_ID_3Mos is missing ) then t1.SRVC_ID_6Mos

else t1.SRVC_ID_6Mos
END) AS CALCULATION
FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt; 78         PROC SQL NOEXEC;
 79         SELECT (CASE
 80         when(t1.SRVC_ID_3Mos is missing ) then t1.SRVC_ID_6Mos
 81         
 82         else t1.SRVC_ID_6Mos
 83         END) AS CALCULATION
 84         FROM WORK.QUERY_FOR_AVG_3MONTHS_NONNULL t1;
 NOTE: Statement not executed due to NOEXEC option.
 85         QUIT;
 NOTE:  Verwendet wurde: PROZEDUR SQL - (Gesamtverarbeitungszeit):
&lt;/PRE&gt;
&lt;P&gt;Start a fresh SAS session and run my code for a test, then run yours.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 08:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CASE-WHEN-Statement/m-p/761089#M240775</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-12T08:16:22Z</dc:date>
    </item>
  </channel>
</rss>

