<?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: Filtering by date proc sql in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Filtering-by-date-proc-sql/m-p/561519#M10603</link>
    <description>&lt;P&gt;So you appear to have a DATETIME variable instead of a DATE variable.&amp;nbsp; Dates are stored as a number of days and datetime values as a number of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also seem to have found a strange feature of SAS.&amp;nbsp; If you add a time part to the literal string in a DATE literal the time part is ignored when converting the string into an actual date value.&amp;nbsp; It doesn't even had to look like a time value, it can any extraneous text because SAS just ignores it once it has 9 characters to convert into a date value.&lt;/P&gt;
&lt;PRE&gt;540  data test;
541   duedate = '23MAY2018:12:10:56'd;
542   put duedate= :comma15. ' ' duedate date9. ' ' duedate datetime20.;
543   duedate = '23MAY2018:blahblah'd;
544   put duedate= :comma15. ' ' duedate date9. ' ' duedate datetime20.;
545  run;

duedate=21,327  23MAY2018   01JAN1960:05:55:27
duedate=21,327  23MAY2018   01JAN1960:05:55:27&lt;/PRE&gt;
&lt;P&gt;So if you want to make an actual DATETIME literal remember to use DT suffix after the quoted string and not just the letter D.&lt;/P&gt;
&lt;PRE&gt;546
547  data test;
548   duedate = '23MAY2018:12:10:56'dt;
549   put duedate= :comma15. ' ' duedate date9. ' ' duedate datetime20.;
550  run;

duedate=1,842,696,656  *********   23MAY2018:12:10:56&lt;/PRE&gt;
&lt;P&gt;Notice how the actual value of the DATETIME value is so much larger than the DATE value.&amp;nbsp; That is because there are 24*60*60=86,400 seconds in a single day.&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2019 20:15:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-05-24T20:15:53Z</dc:date>
    <item>
      <title>Filtering by date proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filtering-by-date-proc-sql/m-p/561506#M10601</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following variable:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Variable&lt;/TD&gt;&lt;TD&gt;Type&lt;/TD&gt;&lt;TD&gt;Len&lt;/TD&gt;&lt;TD&gt;Format&lt;/TD&gt;&lt;TD&gt;Informat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DUEDATE&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;DATETIME20.&lt;/TD&gt;&lt;TD&gt;DATETIME20.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the following query:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql inobs=10;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select duedate from output.mydata;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I show&amp;nbsp;23MAY2018:12:10:56 in the first row. But when I query using the outputted data, no rows are returned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select * from output.mydata&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;where duedate = '23MAY2018:12:10:56'd; &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ultimately I want my where clause to be &lt;STRONG&gt;duedate between '01APR2019'd and '30APR2019'd&lt;/STRONG&gt;, but right now it's not returning anything so I tried the above.&amp;nbsp; Please help.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 18:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filtering-by-date-proc-sql/m-p/561506#M10601</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-05-24T18:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering by date proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filtering-by-date-proc-sql/m-p/561508#M10602</link>
      <description>&lt;P&gt;Got it now, use datepart:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;where datepart(duedate) = '23MAY2018'd&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 18:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filtering-by-date-proc-sql/m-p/561508#M10602</guid>
      <dc:creator>jffeudo86</dc:creator>
      <dc:date>2019-05-24T18:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering by date proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Filtering-by-date-proc-sql/m-p/561519#M10603</link>
      <description>&lt;P&gt;So you appear to have a DATETIME variable instead of a DATE variable.&amp;nbsp; Dates are stored as a number of days and datetime values as a number of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also seem to have found a strange feature of SAS.&amp;nbsp; If you add a time part to the literal string in a DATE literal the time part is ignored when converting the string into an actual date value.&amp;nbsp; It doesn't even had to look like a time value, it can any extraneous text because SAS just ignores it once it has 9 characters to convert into a date value.&lt;/P&gt;
&lt;PRE&gt;540  data test;
541   duedate = '23MAY2018:12:10:56'd;
542   put duedate= :comma15. ' ' duedate date9. ' ' duedate datetime20.;
543   duedate = '23MAY2018:blahblah'd;
544   put duedate= :comma15. ' ' duedate date9. ' ' duedate datetime20.;
545  run;

duedate=21,327  23MAY2018   01JAN1960:05:55:27
duedate=21,327  23MAY2018   01JAN1960:05:55:27&lt;/PRE&gt;
&lt;P&gt;So if you want to make an actual DATETIME literal remember to use DT suffix after the quoted string and not just the letter D.&lt;/P&gt;
&lt;PRE&gt;546
547  data test;
548   duedate = '23MAY2018:12:10:56'dt;
549   put duedate= :comma15. ' ' duedate date9. ' ' duedate datetime20.;
550  run;

duedate=1,842,696,656  *********   23MAY2018:12:10:56&lt;/PRE&gt;
&lt;P&gt;Notice how the actual value of the DATETIME value is so much larger than the DATE value.&amp;nbsp; That is because there are 24*60*60=86,400 seconds in a single day.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 20:15:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Filtering-by-date-proc-sql/m-p/561519#M10603</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-24T20:15:53Z</dc:date>
    </item>
  </channel>
</rss>

