<?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 Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-Result-of-When-clause-2-is-not-the-same-data-type-as-the/m-p/775956#M246681</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I received this error when I tried to do a select distinct in proc SQL:&amp;nbsp;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results. I'm programming in SAS Enterprise Guide 8.3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table OneTerm as&lt;BR /&gt;select drv.TERMS_ID, drv.day, (drv.day+drv.start_dt) as date format&lt;BR /&gt;YYMMDD10., drv.SECTID,&lt;BR /&gt;case when a.CreditHours is missing then 0 else a.CreditHours end as CreditHours,&lt;BR /&gt;case when a.seatcount is missing then 0 else a.seatcount end as seatcount from(select distinct a.TERMS_ID,a.day,&lt;BR /&gt;(a.date-a.day)as start_dt format YYMMDD10., b.SECTID&lt;BR /&gt;from work.ADDREGDAY as a left join&lt;BR /&gt;(select distinct TERMS_ID, SECTID from work.addregday where TERMS_ID="&amp;amp;TERMS_ID" and SECTID is not null)b&lt;BR /&gt;on a.TERMS_ID=b.TERMS_ID where a.TERMS_ID="&amp;amp;Terms_ID") as drv&lt;BR /&gt;left join&lt;BR /&gt;(select * from work.addregday where TERMS_ID="&amp;amp;TERMS_ID") as a&lt;BR /&gt;on drv.day=a.day and drv.SECTID=a.SECTID;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the logs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;277 create table OneTerm as&lt;BR /&gt;278 select drv.TERMS_ID, drv.day, (drv.day+drv.start_dt)&lt;BR /&gt;41 The SAS System&lt;BR /&gt;12:22 Friday, October 22, 2021&lt;/P&gt;&lt;P&gt;278 ! as date format&lt;BR /&gt;279 YYMMDD10., drv.SECTID,&lt;BR /&gt;280 case when a.CreditHours is missing then 0 else&lt;BR /&gt;280 ! a.CreditHours end as CreditHours,&lt;BR /&gt;281 case when a.seatcount is missing then 0 else&lt;BR /&gt;281 ! a.seatcount end as seatcount from(select distinct&lt;BR /&gt;281 ! a.TERMS_ID,a.day,&lt;BR /&gt;282 (a.date-a.day)as start_dt format YYMMDD10., b.SECTID&lt;BR /&gt;283 from work.ADDREGDAY as a left join&lt;BR /&gt;284 (select distinct TERMS_ID, SECTID from work.addregday&lt;BR /&gt;284 ! where TERMS_ID="&amp;amp;TERMS_ID" and SECTID ne .)b&lt;BR /&gt;285 on a.TERMS_ID=b.TERMS_ID where&lt;BR /&gt;42 The SAS System&lt;BR /&gt;12:22 Friday, October 22, 2021&lt;/P&gt;&lt;P&gt;285 ! a.TERMS_ID="&amp;amp;Terms_ID") as drv&lt;BR /&gt;286 left join&lt;BR /&gt;287 (select * from work.addregday where&lt;BR /&gt;287 ! TERMS_ID="&amp;amp;TERMS_ID") as a&lt;BR /&gt;288 on drv.day=a.day and drv.SECTID=a.SECTID;&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the&lt;BR /&gt;preceding results.&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the&lt;BR /&gt;syntax of statements.&lt;BR /&gt;289 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of&lt;BR /&gt;errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone help me with what's going on?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SECTID is a numeric&lt;/P&gt;&lt;P&gt;Day is a numeric&lt;/P&gt;&lt;P&gt;TERMS_ID is a character&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help you can provide.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Oct 2021 19:11:16 GMT</pubDate>
    <dc:creator>cmshearon8845</dc:creator>
    <dc:date>2021-10-22T19:11:16Z</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-Programming/Error-Result-of-When-clause-2-is-not-the-same-data-type-as-the/m-p/775956#M246681</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I received this error when I tried to do a select distinct in proc SQL:&amp;nbsp;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results. I'm programming in SAS Enterprise Guide 8.3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table OneTerm as&lt;BR /&gt;select drv.TERMS_ID, drv.day, (drv.day+drv.start_dt) as date format&lt;BR /&gt;YYMMDD10., drv.SECTID,&lt;BR /&gt;case when a.CreditHours is missing then 0 else a.CreditHours end as CreditHours,&lt;BR /&gt;case when a.seatcount is missing then 0 else a.seatcount end as seatcount from(select distinct a.TERMS_ID,a.day,&lt;BR /&gt;(a.date-a.day)as start_dt format YYMMDD10., b.SECTID&lt;BR /&gt;from work.ADDREGDAY as a left join&lt;BR /&gt;(select distinct TERMS_ID, SECTID from work.addregday where TERMS_ID="&amp;amp;TERMS_ID" and SECTID is not null)b&lt;BR /&gt;on a.TERMS_ID=b.TERMS_ID where a.TERMS_ID="&amp;amp;Terms_ID") as drv&lt;BR /&gt;left join&lt;BR /&gt;(select * from work.addregday where TERMS_ID="&amp;amp;TERMS_ID") as a&lt;BR /&gt;on drv.day=a.day and drv.SECTID=a.SECTID;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the logs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;277 create table OneTerm as&lt;BR /&gt;278 select drv.TERMS_ID, drv.day, (drv.day+drv.start_dt)&lt;BR /&gt;41 The SAS System&lt;BR /&gt;12:22 Friday, October 22, 2021&lt;/P&gt;&lt;P&gt;278 ! as date format&lt;BR /&gt;279 YYMMDD10., drv.SECTID,&lt;BR /&gt;280 case when a.CreditHours is missing then 0 else&lt;BR /&gt;280 ! a.CreditHours end as CreditHours,&lt;BR /&gt;281 case when a.seatcount is missing then 0 else&lt;BR /&gt;281 ! a.seatcount end as seatcount from(select distinct&lt;BR /&gt;281 ! a.TERMS_ID,a.day,&lt;BR /&gt;282 (a.date-a.day)as start_dt format YYMMDD10., b.SECTID&lt;BR /&gt;283 from work.ADDREGDAY as a left join&lt;BR /&gt;284 (select distinct TERMS_ID, SECTID from work.addregday&lt;BR /&gt;284 ! where TERMS_ID="&amp;amp;TERMS_ID" and SECTID ne .)b&lt;BR /&gt;285 on a.TERMS_ID=b.TERMS_ID where&lt;BR /&gt;42 The SAS System&lt;BR /&gt;12:22 Friday, October 22, 2021&lt;/P&gt;&lt;P&gt;285 ! a.TERMS_ID="&amp;amp;Terms_ID") as drv&lt;BR /&gt;286 left join&lt;BR /&gt;287 (select * from work.addregday where&lt;BR /&gt;287 ! TERMS_ID="&amp;amp;TERMS_ID") as a&lt;BR /&gt;288 on drv.day=a.day and drv.SECTID=a.SECTID;&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the&lt;BR /&gt;preceding results.&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the&lt;BR /&gt;syntax of statements.&lt;BR /&gt;289 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of&lt;BR /&gt;errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone help me with what's going on?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SECTID is a numeric&lt;/P&gt;&lt;P&gt;Day is a numeric&lt;/P&gt;&lt;P&gt;TERMS_ID is a character&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help you can provide.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Oct 2021 19:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-Result-of-When-clause-2-is-not-the-same-data-type-as-the/m-p/775956#M246681</guid>
      <dc:creator>cmshearon8845</dc:creator>
      <dc:date>2021-10-22T19:11:16Z</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-Programming/Error-Result-of-When-clause-2-is-not-the-same-data-type-as-the/m-p/775957#M246682</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when a.seatcount is missing then 0 else a.seatcount end as seatcount&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;a.seatcount is likely a character variable, and you can't sometimes assign a.seatcount (a character value) and sometimes assign 0 (a numeric value) to the same variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make a.seatcount into a numeric variable.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Oct 2021 19:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-Result-of-When-clause-2-is-not-the-same-data-type-as-the/m-p/775957#M246682</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-22T19:34:26Z</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-Programming/Error-Result-of-When-clause-2-is-not-the-same-data-type-as-the/m-p/775958#M246683</link>
      <description>&lt;P&gt;You might want to think about your definition of the alias A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(a.date-a.day)as start_dt format YYMMDD10., b.SECTID
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;from work.ADDREGDAY as a&lt;/STRONG&gt;&lt;/FONT&gt; left join
(select distinct TERMS_ID, SECTID from work.addregday where TERMS_ID="&amp;amp;TERMS_ID" and SECTID is not null)b
on a.TERMS_ID=b.TERMS_ID where a.TERMS_ID="&amp;amp;Terms_ID") as drv
left join
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;(select * from work.addregday where TERMS_ID="&amp;amp;TERMS_ID") as a&lt;/STRONG&gt;&lt;/FONT&gt;
on drv.day=a.day and drv.SECTID=a.SECTID;
quit;&lt;/PRE&gt;
&lt;P&gt;With more than one A are you sure that the CASE statement is using the right one? If both A have a variable in common but different types that could be an issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Back out the multiple joins to just the variables in the Case statements and test. I am not&amp;nbsp; sure why you bothered to point out those variables, the Case statement When clauses are using Credithours and Seatcount. Those would be variables to look at.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please consider formatting your code as it is very hard to follow. Paste code into a code box opened on the forum with the "running man" or &amp;lt;/&amp;gt; icons that appear above the message windows. Log text should go into a text box opened with the &amp;lt;/&amp;gt; icon.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Oct 2021 19:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-Result-of-When-clause-2-is-not-the-same-data-type-as-the/m-p/775958#M246683</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-22T19:28:01Z</dc:date>
    </item>
  </channel>
</rss>

