<?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: ERROR: Result of WHEN clause 2 is not the same data type as the preceding results. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268471#M18595</link>
    <description>&lt;P&gt;No probs. &amp;nbsp;So the variable that this applies to is a numeric date variable, i.e. its not the table.close_date as that is character? &amp;nbsp;Its hard to say not knowing how the query builder works as your case when seems wrong, you wouldn't then &amp;lt;assignment&amp;gt;.&lt;/P&gt;
&lt;P&gt;In actual code a case would look like:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select case when CLOSE_DATE='0000-00-00' then .
              else input(CLOSE_DATE,best8.) end as RESULT_VARIABLE
  from   TABLE;
quit;&lt;/PRE&gt;
&lt;P&gt;So we are saying if close_date is the character string '0000-00-00', then the result of the clause will be missing (.). &amp;nbsp;Otherwise input the character string from close_date into a numeric result. &amp;nbsp;The as sets RESULT_VARIABLE which is a numeric variable to either . or the numeric version of close_date.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 May 2016 09:42:42 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-05-05T09:42:42Z</dc:date>
    <item>
      <title>ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268462#M18592</link>
      <description>&lt;P&gt;Good day,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS EG 9.1.3 and cannot resolve this error: ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;/P&gt;
&lt;P&gt;It is a&amp;nbsp;simple case statement using the query builder:&lt;/P&gt;
&lt;P&gt;The column CLOSE_DATE is a character and the THEN attempts to put in a blank.&lt;/P&gt;
&lt;P&gt;CASE&amp;nbsp; WHEN (TABLE.CLOSE_DATE = '0000-00-00') THEN (CLOSE_DATE = '') ELSE TABLE.CLOSE_DATE END&lt;/P&gt;
&lt;P&gt;If not a CASE statement, what could I use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2016 08:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268462#M18592</guid>
      <dc:creator>ahtinuS</dc:creator>
      <dc:date>2016-05-05T08:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268468#M18593</link>
      <description>&lt;P&gt;I don't use EG, but it sounds like a variable is not being found, and looking at your example, why specify the table name each time other than the assignment (also please don't code all in upper case its very hard to read):&lt;/P&gt;
&lt;PRE&gt;case  when (table.close_date = '0000-00-00') then (table.close_date = '') else table.close_date end&lt;BR /&gt;                                                   ^     ^&lt;/PRE&gt;
&lt;P&gt;As I asy, I don't use EG, so don't know about this query builder, but in normal code you could just do:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;table.close_date=tranwrd(table.close_date,"0000-00-00","");&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 May 2016 08:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268468#M18593</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-05T08:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268469#M18594</link>
      <description>&lt;P&gt;Apologies for the caps and using the table name - this is the way SAS EG query builder writes the query, I have converted to lower case for ease of reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did manage to resolve the error but it created a new problem.&lt;/P&gt;
&lt;P&gt;I get a 0 which&amp;nbsp;then converts to SAS date 1Jan1960 instead of a blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The fix was:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;case when (table.close_date = '0000-00-00')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then (table.close_date = '')&lt;/P&gt;
&lt;P&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; else input(table.close_date,best8.)&lt;/P&gt;
&lt;P&gt;end&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that it was looking for a numeric instead of a character.&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2016 09:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268469#M18594</guid>
      <dc:creator>ahtinuS</dc:creator>
      <dc:date>2016-05-05T09:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268471#M18595</link>
      <description>&lt;P&gt;No probs. &amp;nbsp;So the variable that this applies to is a numeric date variable, i.e. its not the table.close_date as that is character? &amp;nbsp;Its hard to say not knowing how the query builder works as your case when seems wrong, you wouldn't then &amp;lt;assignment&amp;gt;.&lt;/P&gt;
&lt;P&gt;In actual code a case would look like:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select case when CLOSE_DATE='0000-00-00' then .
              else input(CLOSE_DATE,best8.) end as RESULT_VARIABLE
  from   TABLE;
quit;&lt;/PRE&gt;
&lt;P&gt;So we are saying if close_date is the character string '0000-00-00', then the result of the clause will be missing (.). &amp;nbsp;Otherwise input the character string from close_date into a numeric result. &amp;nbsp;The as sets RESULT_VARIABLE which is a numeric variable to either . or the numeric version of close_date.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2016 09:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268471#M18595</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-05T09:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268487#M18597</link>
      <description>&lt;P&gt;I think I see part of your problem. The CASE statement in the EG query builder is a bit of an odd fish, due to the fact that the underlying code is SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally, what you should be be supplying is just the RESULT of calculation, and the SQL code will do the assignment. So if I wanted to assign values of YOUNG or OLD to a variable based on age, I would do it like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;case when (age &amp;lt; 18)&lt;BR /&gt;then ('YOUNG')&lt;BR /&gt;else ('OLD')&lt;BR /&gt;end&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try restructuring your query along these lines, and see if it works.&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2016 12:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268487#M18597</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2016-05-05T12:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268553#M18602</link>
      <description>&lt;P&gt;The logic of your original code may be ok, &amp;nbsp;change &amp;nbsp;'' to ' '. Insert a space between the quote marks. &amp;nbsp;Quotes without a blank between is a null value which can be interpreted as a missing value. Which would explain the different data types error. &amp;nbsp;Hope this helps&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2016 14:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-Result-of-WHEN-clause-2-is-not-the-same-data-type-as-the/m-p/268553#M18602</guid>
      <dc:creator>thorneton</dc:creator>
      <dc:date>2016-05-05T14:50:03Z</dc:date>
    </item>
  </channel>
</rss>

