<?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 in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370225#M275673</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/149564"&gt;@teddyee&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Your condition&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;WHEN A.RBK_Last_Contactdate ='' and B.RBK_Last_Contactdate =''&lt;/EM&gt; only becomes TRUE when both variables are missing and though the max() will always be missing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your CASE statement is also missing an ELSE case so when one of the two variables isn't missing then nothing happens and you also end up with a missing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And last but not least:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your code indicates that you're dealing with numerical variables so your comparison&amp;nbsp;should be&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;A.RBK_Last_Contactdate=&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt; and not&amp;nbsp;&lt;EM&gt;A.RBK_Last_Contactdate=&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;' '&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I believe what you're after is something like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;CASE &lt;BR /&gt; WHEN cmiss(A.RBK_Last_Contactdate,B.RBK_Last_Contactdate)&amp;gt;0 &lt;BR /&gt; THEN coalesce(A.RBK_Last_Contactdate,B.RBK_Last_Contactdate)&lt;BR /&gt; else &amp;lt;some other value&amp;gt;&lt;BR /&gt; END AS RBK_Last_Contactdate FORMAT DATE9.&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Function CMISS() works for both character and numeric variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And for development and debugging purposes: Make your code work without macro syntax and only implement the macro bits once your code works.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 24 Jun 2017 05:35:06 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-06-24T05:35:06Z</dc:date>
    <item>
      <title>Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370221#M275671</link>
      <description>&lt;P&gt;%MACRO C(CURR_DATE=,PCURR_DATE=, B=);&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE ADHOC.FINAL1_&amp;amp;B._&amp;amp;CURR_DATE. AS&lt;BR /&gt;SELECT A.Customer_IC_No&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;, CASE WHEN A.RBK_Last_Contactdate ='' and B.RBK_Last_Contactdate ='' THEN Max(A.RBK_Last_Contactdate,B.RBK_Last_Contactdate)&lt;BR /&gt;END AS RBK_Last_Contactdate FORMAT DATE9.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;END AS new_filter&lt;/P&gt;&lt;P&gt;FROM ADHOC.final_&amp;amp;B._&amp;amp;PCURR_DATE. A&lt;BR /&gt;LEFT JOIN ADHOC.final_&amp;amp;B._&amp;amp;CURR_DATE. B&lt;BR /&gt;ON A.Customer_IC_No=B.Customer_IC_No&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%MEND;&lt;BR /&gt;%C(CURR_DATE=20170602,PCURR_DATE=20170601, B=M);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question: In this example how do i use case when to get the latest date of the same variable from 2 files?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2017 04:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370221#M275671</guid>
      <dc:creator>teddyee</dc:creator>
      <dc:date>2017-06-24T04:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370224#M275672</link>
      <description>&lt;P&gt;found it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to replace with this line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;, CASE WHEN COALESCE(A.RBK_Last_Contactdate, B.RBK_Last_Contactdate) is not null THEN max(A.RBK_Last_Contactdate, B.RBK_Last_Contactdate)&lt;BR /&gt;END AS RBK_Last_Contactdate FORMAT DATE9.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2017 05:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370224#M275672</guid>
      <dc:creator>teddyee</dc:creator>
      <dc:date>2017-06-24T05:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370225#M275673</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/149564"&gt;@teddyee&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Your condition&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;WHEN A.RBK_Last_Contactdate ='' and B.RBK_Last_Contactdate =''&lt;/EM&gt; only becomes TRUE when both variables are missing and though the max() will always be missing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your CASE statement is also missing an ELSE case so when one of the two variables isn't missing then nothing happens and you also end up with a missing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And last but not least:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your code indicates that you're dealing with numerical variables so your comparison&amp;nbsp;should be&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;A.RBK_Last_Contactdate=&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt; and not&amp;nbsp;&lt;EM&gt;A.RBK_Last_Contactdate=&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;' '&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I believe what you're after is something like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;CASE &lt;BR /&gt; WHEN cmiss(A.RBK_Last_Contactdate,B.RBK_Last_Contactdate)&amp;gt;0 &lt;BR /&gt; THEN coalesce(A.RBK_Last_Contactdate,B.RBK_Last_Contactdate)&lt;BR /&gt; else &amp;lt;some other value&amp;gt;&lt;BR /&gt; END AS RBK_Last_Contactdate FORMAT DATE9.&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Function CMISS() works for both character and numeric variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And for development and debugging purposes: Make your code work without macro syntax and only implement the macro bits once your code works.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2017 05:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370225#M275673</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-24T05:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370227#M275674</link>
      <description>&lt;P&gt;thanks it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;another question: let's say if i want to get the&amp;nbsp;max of the following characher Y, N, or missing variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;any solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 24 Jun 2017 06:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370227#M275674</guid>
      <dc:creator>teddyee</dc:creator>
      <dc:date>2017-06-24T06:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Case when in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370230#M275675</link>
      <description>let's say if i want to return a value&lt;BR /&gt;by ranking:&lt;BR /&gt;C&amp;gt;B&amp;gt;A&amp;gt;null&lt;BR /&gt;&lt;BR /&gt;any proc sql code to get the max of the character?&lt;BR /&gt;&lt;BR /&gt;i can get max of a numeric value, how to apply the same for character?&lt;BR /&gt;</description>
      <pubDate>Sat, 24 Jun 2017 07:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-in-SQL/m-p/370230#M275675</guid>
      <dc:creator>teddyee</dc:creator>
      <dc:date>2017-06-24T07:16:34Z</dc:date>
    </item>
  </channel>
</rss>

