<?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: PROC SQL condition on datetime date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623117#M183374</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/211631"&gt;@newboy1218&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried this, assuming the date variable is a SAS Date with the format you specified&lt;SPAN style="white-space: pre; background-color: #eaeaea;"&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (datepart(snapshot_creation_date) &amp;gt;= '01JAN2019'd and datepart(snapshot_creation_date) &amp;lt;= '31DEC2019'd)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NB: please check the condition (&amp;lt;= / &amp;gt;=)&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
    <pubDate>Fri, 07 Feb 2020 16:54:39 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-02-07T16:54:39Z</dc:date>
    <item>
      <title>PROC SQL condition on datetime date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623110#M183369</link>
      <description>&lt;P&gt;Hi, in my proc sql statement, I want to apply a where condition on the date variable. The date variable has datetime20. format, for example:&amp;nbsp; 17APR2016:07:57:23&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where&amp;nbsp;(snapshot_creation_date &amp;lt;= '2019-12-01' and snapshot_creation_date &amp;gt;= '2019-12-31')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I got the error saying:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Expression using greater than or equal (&amp;gt;=) has components that are of different data&lt;BR /&gt;types.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What can I change to make this works? Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623110#M183369</guid>
      <dc:creator>newboy1218</dc:creator>
      <dc:date>2020-02-07T16:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL condition on datetime date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623116#M183373</link>
      <description>&lt;P&gt;To compare SAS date values to a literal date the format &lt;STRONG&gt;must&lt;/STRONG&gt; be a date9 or date7 value quoted and followed with a d such as '01DEC2019'd. Second you would want to compare the DATEPART of a datetime value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example to select records in Dec of 2019 you might use:&lt;/P&gt;
&lt;PRE&gt;where ('01DEC2019'd &amp;lt;= datepart(snapshot_creation_date) &amp;lt;= '31DEC2019'd)&lt;/PRE&gt;
&lt;P&gt;note that your original code would only return values &amp;gt;= 31Dec2019 if it had worked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will allow doing a sequential comparison without having to do an "and" with two separate ranges.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623116#M183373</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-07T16:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL condition on datetime date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623117#M183374</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/211631"&gt;@newboy1218&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried this, assuming the date variable is a SAS Date with the format you specified&lt;SPAN style="white-space: pre; background-color: #eaeaea;"&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (datepart(snapshot_creation_date) &amp;gt;= '01JAN2019'd and datepart(snapshot_creation_date) &amp;lt;= '31DEC2019'd)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NB: please check the condition (&amp;lt;= / &amp;gt;=)&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623117#M183374</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T16:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL condition on datetime date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623118#M183375</link>
      <description>&lt;P&gt;The problem is because you asked SAS to compare a number (datetime values are the number of seconds since 1960) to a string.&lt;/P&gt;
&lt;P&gt;To make a datetime literal you need to use a string that the DATETIME informat can read with the letters DT after the closing quote.&lt;/P&gt;
&lt;P&gt;Also what do you want to do with values like:&amp;nbsp; '01DEC2019:10:30'dt or '31DEC2019:09:30'dt?&lt;/P&gt;
&lt;P&gt;Perhaps you just want to do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where snapshot_creation_date &amp;lt; '02DEC2019:00:00'dt
  and snapshot_creation_date &amp;gt;= '01JAN2020:00:00'dt&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 16:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-condition-on-datetime-date/m-p/623118#M183375</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-07T16:56:00Z</dc:date>
    </item>
  </channel>
</rss>

