<?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 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/785958#M39976</link>
    <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;My below query is resulting in error "Result of WHEN clause 2 is not the same data type as the preceding results."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;case&lt;BR /&gt;when adjud_dt ='' then paid_dt&lt;BR /&gt;else adjud_dt&lt;BR /&gt;end as new_adjud_dt format = date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;adjud_dt and paid_dt both are formatted as date9. in the data on which i am running this code.&lt;/P&gt;&lt;P&gt;Could anyone please advise how to resolve this issue.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Dec 2021 10:18:05 GMT</pubDate>
    <dc:creator>ratnaparakhee</dc:creator>
    <dc:date>2021-12-14T10:18:05Z</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/785958#M39976</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;My below query is resulting in error "Result of WHEN clause 2 is not the same data type as the preceding results."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;case&lt;BR /&gt;when adjud_dt ='' then paid_dt&lt;BR /&gt;else adjud_dt&lt;BR /&gt;end as new_adjud_dt format = date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;adjud_dt and paid_dt both are formatted as date9. in the data on which i am running this code.&lt;/P&gt;&lt;P&gt;Could anyone please advise how to resolve this issue.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 10:18:05 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/785958#M39976</guid>
      <dc:creator>ratnaparakhee</dc:creator>
      <dc:date>2021-12-14T10:18:05Z</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/785959#M39977</link>
      <description>&lt;P&gt;Maxim 3: Know Your Data. Run a PROC CONTENTS to see the types of the variables paid_dt and adjud_dt.&lt;/P&gt;
&lt;P&gt;Since you (successfully, as it seems) compare adjud_dt with an empty &lt;EM&gt;string&lt;/EM&gt;, it can't be a SAS date (which is numeric with a date format assigned).&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 10:49:00 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/785959#M39977</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-14T10:49:00Z</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/785970#M39978</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for looking into my issue.&lt;/P&gt;&lt;P&gt;I did check the type of my fields, both are format date 9. and type Num. please see below-&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ratnaparakhee_0-1639481533136.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66748iBE7EA535E6B4A95D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ratnaparakhee_0-1639481533136.png" alt="ratnaparakhee_0-1639481533136.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Apart from using case when ADJUD_DT = '' , i also tried&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;case when ADJUD_DT is null and&lt;/P&gt;&lt;P&gt;case when ADJUD_DT is missing and both are giving the same error.&lt;/P&gt;&lt;P&gt;I also wanted to add that i am running this query on 2 data sets. Source of one is Netezza and second is oracle.&lt;/P&gt;&lt;P&gt;This runs fine on data extracted on Netezza but errors out for data extracted from oracle.&lt;/P&gt;&lt;P&gt;Does this give you any additional insights that might help resolving this issue?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 11:36:12 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/785970#M39978</guid>
      <dc:creator>ratnaparakhee</dc:creator>
      <dc:date>2021-12-14T11:36:12Z</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/785975#M39979</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409870"&gt;@ratnaparakhee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for looking into my issue.&lt;/P&gt;
&lt;P&gt;I did check the type of my fields, both are format date 9. and type Num. please see below-&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ratnaparakhee_0-1639481533136.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66748iBE7EA535E6B4A95D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ratnaparakhee_0-1639481533136.png" alt="ratnaparakhee_0-1639481533136.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You only showed one variable. What about PAID_DT?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, as stated above, you can't test to see if a numeric variable ADJUD_DT is equal to a character string.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 11:47:08 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/785975#M39979</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-14T11:47:08Z</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/785978#M39980</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;the second variable Paid_dt is also same type and format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ratnaparakhee_0-1639482559510.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66750i3C83143E6B7BF58F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ratnaparakhee_0-1639482559510.png" alt="ratnaparakhee_0-1639482559510.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 11:51:14 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/785978#M39980</guid>
      <dc:creator>ratnaparakhee</dc:creator>
      <dc:date>2021-12-14T11:51:14Z</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/785979#M39981</link>
      <description>&lt;P&gt;So then&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has correctly pointed to the problem, you can't test to see if a numeric variable ADJUD_DT is equal to a character string.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 11:52:53 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/785979#M39981</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-14T11:52:53Z</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/785981#M39982</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In that case could you please advise what should i compare it against.&lt;/P&gt;&lt;P&gt;I am new to SAS. In addition to '' i also cehck with&amp;nbsp;&lt;/P&gt;&lt;P&gt;When adjud_dt is missing&amp;nbsp; and&amp;nbsp;&lt;/P&gt;&lt;P&gt;when adjud_dt is null&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both resulted in the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Bhawna&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 11:59:18 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/785981#M39982</guid>
      <dc:creator>ratnaparakhee</dc:creator>
      <dc:date>2021-12-14T11:59:18Z</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/785983#M39983</link>
      <description>&lt;P&gt;You can use the MISSING function, which works on both numeric and character variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when missing(adjud_dt) then paid_dt&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Dec 2021 12:09:14 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/785983#M39983</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-14T12:09:14Z</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/785984#M39984</link>
      <description>&lt;P&gt;If you had a numeric variable and tried to compare it with an empty string, SAS would issue&lt;/P&gt;
&lt;PRE&gt;ERROR: Expression using equals (=) has components that are of different data types.
 &lt;/PRE&gt;
&lt;P&gt;Reference code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select
  case when age = ""
    then weight
    else age
  end as new
from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since you did not get that, the variable IS character, period.&lt;/P&gt;
&lt;P&gt;Run the PROC CONTENTS on &lt;U&gt;all&lt;/U&gt; datasets involved in the query; it may be that you have variables with the same name in more than one dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 12:14:47 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/785984#M39984</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-14T12:14:47Z</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/787273#M40034</link>
      <description>&lt;P&gt;The problem with your code is the statement when &lt;STRONG&gt;adjud_dt =&lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;''&lt;/FONT&gt; then paid_dt.&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Date being a numeric one must use &lt;STRONG&gt;adjud_dt =&lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt; . &lt;FONT color="#000000"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;This is because missing numeric values are represented by a dot or period and not as used in the code.&lt;BR /&gt;The two single quotes as used in the code posted indicate a missing character value. That is what the error message is indicating. I am giving the sample code below which works correctly.&lt;BR /&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data old;
informat adjud_dt  paid_dt date9.;
format adjud_dt  paid_dt date9.;
input adjud_dt  paid_dt;
datalines;
23DEC2021 22DEC2021
20DEC2021 21DEC2021
 .                  19DEC2021
 ;
 run;
proc sql;
create table new as
select *,
case
when adjud_dt=.  then paid_dt
else adjud_dt
end as new_adjud_dt format date9. 
from old;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;one can also use missing function as shown by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; , in that case the sql statement would be as follows&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table new as
select *,
case
when missing(adjud_dt)  then paid_dt
else adjud_dt
end as new_adjud_dt format date9. 
from old;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Either way the result is same.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 18:25:41 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/787273#M40034</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-12-23T18:25:41Z</dc:date>
    </item>
  </channel>
</rss>

