<?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 The error Expression using IN has components that are of different data types&amp;amp;quot; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-error-Expression-using-IN-has-components-that-are-of/m-p/867142#M342457</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've been running and staring at this code but can't figure out this error.&lt;/P&gt;&lt;P&gt;I believe my components are the same type - a datetime and date literals . I don't have an IN function in my code so where is that coming from? I included code that runs without problems at the bottom of the code, and it uses this &lt;EM&gt;admitdatetime between '2018-10-01' and '2019-9-30'.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Diane&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;	proc sql;
	create table scr as select a.*, case when 
		b.patientsid is null then 'O' else 'I'
		end as IP_OR_OP
		from scr0 a left join inpat_inpatient b on 
	a.patientsid=b.patientsid
	where 
admitdatetime&amp;gt;='2018-10-01 00.00.00' and admitdatetime
&amp;lt;'2019-10-01 00.00.00' ; 

/*&amp;gt; Also tried between '20181001' and '20191001'
between '2018-10-01'
and '2019-10.01'
admitdatetime&amp;gt;='2018-10-01 00:00:000000' and admitdatetime
&amp;lt;'2018-10-01 00:00:000000'
 
AdmitDateTime is datetime20 format. Is the date constant not compatible
with datetime?

*/

 quit;


ERROR: Expression using greater than or equal (&amp;gt;=) has components that are of different data types.
NOTE: The IN referred to may have been transformed from an OR to an IN at some point during PROC SQL WHERE clause optimization.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
39       !   quit;

THIS WORKS FINE:
proc sql;
CONNECT TO SQLSVR AS CDW(DATAsrc=&amp;lt;project name&amp;gt; &amp;amp;SQL_OPTIMAL.);
create table inpat_inpatient as select * from
 connection to cdw
(select patientsid,admitdatetime,dischargedatetime from
src.inpat_inpatient
where admitdatetime between '2018-10-01'and '2019-09-30';);
disconnect from cdw;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Mar 2023 22:24:23 GMT</pubDate>
    <dc:creator>steffick</dc:creator>
    <dc:date>2023-03-29T22:24:23Z</dc:date>
    <item>
      <title>The error Expression using IN has components that are of different data types&amp;quot;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-error-Expression-using-IN-has-components-that-are-of/m-p/867142#M342457</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've been running and staring at this code but can't figure out this error.&lt;/P&gt;&lt;P&gt;I believe my components are the same type - a datetime and date literals . I don't have an IN function in my code so where is that coming from? I included code that runs without problems at the bottom of the code, and it uses this &lt;EM&gt;admitdatetime between '2018-10-01' and '2019-9-30'.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Diane&lt;/P&gt;&lt;P&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;	proc sql;
	create table scr as select a.*, case when 
		b.patientsid is null then 'O' else 'I'
		end as IP_OR_OP
		from scr0 a left join inpat_inpatient b on 
	a.patientsid=b.patientsid
	where 
admitdatetime&amp;gt;='2018-10-01 00.00.00' and admitdatetime
&amp;lt;'2019-10-01 00.00.00' ; 

/*&amp;gt; Also tried between '20181001' and '20191001'
between '2018-10-01'
and '2019-10.01'
admitdatetime&amp;gt;='2018-10-01 00:00:000000' and admitdatetime
&amp;lt;'2018-10-01 00:00:000000'
 
AdmitDateTime is datetime20 format. Is the date constant not compatible
with datetime?

*/

 quit;


ERROR: Expression using greater than or equal (&amp;gt;=) has components that are of different data types.
NOTE: The IN referred to may have been transformed from an OR to an IN at some point during PROC SQL WHERE clause optimization.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
39       !   quit;

THIS WORKS FINE:
proc sql;
CONNECT TO SQLSVR AS CDW(DATAsrc=&amp;lt;project name&amp;gt; &amp;amp;SQL_OPTIMAL.);
create table inpat_inpatient as select * from
 connection to cdw
(select patientsid,admitdatetime,dischargedatetime from
src.inpat_inpatient
where admitdatetime between '2018-10-01'and '2019-09-30';);
disconnect from cdw;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 22:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-error-Expression-using-IN-has-components-that-are-of/m-p/867142#M342457</guid>
      <dc:creator>steffick</dc:creator>
      <dc:date>2023-03-29T22:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: The error Expression using IN has components that are of different data types&amp;quot;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-error-Expression-using-IN-has-components-that-are-of/m-p/867145#M342458</link>
      <description>you can't compare admitdatetime, which is numeric, to '2018-10-01 00.00.00' which is a character string. SAS cannot compare a numeric to a character string. However if you use '01OCT2018:00:00:00'dt, SAS knows this is a numeric date/time value and then the comparison works.</description>
      <pubDate>Wed, 29 Mar 2023 22:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-error-Expression-using-IN-has-components-that-are-of/m-p/867145#M342458</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-29T22:45:52Z</dc:date>
    </item>
  </channel>
</rss>

