<?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 Where DATETIME20. variable=ddmmyyyy in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Where-DATETIME20-variable-ddmmyyyy/m-p/811256#M319966</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am creating a table below and have a where clause, where I want to select observations where the DATE variable (which has a DATETIME20. format) is on the day of 31 Mar 2022. Please can someone correct my code (specifically the line of code where the where clause is, as my code is currently returning zero observations) that I have included below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, in the examples below, the code would keep the last three observations (highlighted in red below) because they are within the day of 31 Mar 2022:&lt;/P&gt;
&lt;P&gt;There will be observations in the DATE variable, such as 01MAR202211:12:20:33, 01MAR202211:12:20:34,&amp;nbsp;01MAR202211:12:20:35, &lt;FONT color="#FF0000"&gt;31MAR202212:12:20:33&lt;/FONT&gt;,&lt;FONT color="#FF0000"&gt;31MAR202212:12:20:34&lt;/FONT&gt;,&amp;nbsp;&lt;FONT color="#FF0000"&gt;31MAR202212:12:20:35&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table checks as
    select date
              , value
    from ac.database
    &lt;FONT color="#FF0000"&gt;where ppn_dt="31Mar2022"d ;&lt;/FONT&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 May 2022 15:19:34 GMT</pubDate>
    <dc:creator>Justin9</dc:creator>
    <dc:date>2022-05-03T15:19:34Z</dc:date>
    <item>
      <title>Where DATETIME20. variable=ddmmyyyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-DATETIME20-variable-ddmmyyyy/m-p/811256#M319966</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am creating a table below and have a where clause, where I want to select observations where the DATE variable (which has a DATETIME20. format) is on the day of 31 Mar 2022. Please can someone correct my code (specifically the line of code where the where clause is, as my code is currently returning zero observations) that I have included below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, in the examples below, the code would keep the last three observations (highlighted in red below) because they are within the day of 31 Mar 2022:&lt;/P&gt;
&lt;P&gt;There will be observations in the DATE variable, such as 01MAR202211:12:20:33, 01MAR202211:12:20:34,&amp;nbsp;01MAR202211:12:20:35, &lt;FONT color="#FF0000"&gt;31MAR202212:12:20:33&lt;/FONT&gt;,&lt;FONT color="#FF0000"&gt;31MAR202212:12:20:34&lt;/FONT&gt;,&amp;nbsp;&lt;FONT color="#FF0000"&gt;31MAR202212:12:20:35&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table checks as
    select date
              , value
    from ac.database
    &lt;FONT color="#FF0000"&gt;where ppn_dt="31Mar2022"d ;&lt;/FONT&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2022 15:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-DATETIME20-variable-ddmmyyyy/m-p/811256#M319966</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2022-05-03T15:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Where DATETIME20. variable=ddmmyyyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Where-DATETIME20-variable-ddmmyyyy/m-p/811262#M319967</link>
      <description>&lt;P&gt;DATETIME values are number of seconds.&amp;nbsp; DATE values are number of days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just convert the seconds into days, then your equality test will work.&amp;nbsp; SAS has a function to make it easier called DATEPART().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where datepart(ppn_dt)="31Mar2022"d ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are pulling from a remote database you might get better performance by not requiring the function call.&amp;nbsp; Instead test for a range of seconds (datetime values).&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where "31Mar2022:00:00"dt &amp;lt;= ppn_dt &amp;lt; "01APR2022:00:00"dt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 May 2022 15:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Where-DATETIME20-variable-ddmmyyyy/m-p/811262#M319967</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-03T15:22:53Z</dc:date>
    </item>
  </channel>
</rss>

