<?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: Calculate Date Range in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Range/m-p/743759#M232932</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/383338"&gt;@sharmams0978&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datetime column that has values such as shown below as a sample&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;04MAY2018:08:46:20.316999912&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;11JAN2021:11:07:37.048000097&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;17MAR2019:00:24:55.558000088&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how do I filter the whole table based on the above column date range say between 04MAY2018 AND 17MAR2019? I tried this:&amp;nbsp;WHERE DATE BETWEEN "04MAY2018"d AND "17MAr2019"d but it doesn't work. Please help.. thank you.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, you can't compare a Date-Time variable with a Date value.&amp;nbsp; Date-Time variables are much larger, and it will not be a valid comparison.&amp;nbsp; If you want to use a date range, the DATEPART function should do the trick.&amp;nbsp; Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Filtered_Data;
    SET Unfiltered_Data;

     IF  '04MAY2018'd &amp;lt; DATEPART(Datetime_Column) &amp;lt; '17MAR2019'd;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 May 2021 05:06:00 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-05-26T05:06:00Z</dc:date>
    <item>
      <title>Calculate Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Range/m-p/743747#M232929</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a datetime column that has values such as shown below as a sample&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;04MAY2018:08:46:20.316999912&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11JAN2021:11:07:37.048000097&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;17MAR2019:00:24:55.558000088&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how do I filter the whole table based on the above column date range say between 04MAY2018 AND 17MAR2019? I tried this:&amp;nbsp;WHERE DATE BETWEEN "04MAY2018"d AND "17MAr2019"d but it doesn't work. Please help.. thank you.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 26 May 2021 03:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Range/m-p/743747#M232929</guid>
      <dc:creator>sharmams0978</dc:creator>
      <dc:date>2021-05-26T03:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Range/m-p/743759#M232932</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/383338"&gt;@sharmams0978&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datetime column that has values such as shown below as a sample&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;04MAY2018:08:46:20.316999912&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;11JAN2021:11:07:37.048000097&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;17MAR2019:00:24:55.558000088&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how do I filter the whole table based on the above column date range say between 04MAY2018 AND 17MAR2019? I tried this:&amp;nbsp;WHERE DATE BETWEEN "04MAY2018"d AND "17MAr2019"d but it doesn't work. Please help.. thank you.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, you can't compare a Date-Time variable with a Date value.&amp;nbsp; Date-Time variables are much larger, and it will not be a valid comparison.&amp;nbsp; If you want to use a date range, the DATEPART function should do the trick.&amp;nbsp; Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Filtered_Data;
    SET Unfiltered_Data;

     IF  '04MAY2018'd &amp;lt; DATEPART(Datetime_Column) &amp;lt; '17MAR2019'd;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 05:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Range/m-p/743759#M232932</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-05-26T05:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Range/m-p/743773#M232941</link>
      <description>&lt;P&gt;The problem is that your values are datetimes, not dates. Unlike e.g. T-SQL, where you can compare dates and datetimes directly, you will either have to convert the datetimes in the table to dates (using the DATEPART function, as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;) or use datetime constants in your comparison. I would go with the last solution, as it executes faster (datepart does an extra calculation for every single row in the table):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select * from have where
  datetime_column&amp;gt;='04may2018:00:00:00'dt and
  datetime_column&amp;lt;'18mar2019:00:00:00'dt
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I changed the BETWEEN construct, in order to get exactly the same result as you would with BETWEEN on the dateparts and the dates you mentioned.&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 08:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Range/m-p/743773#M232941</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-05-26T08:24:07Z</dc:date>
    </item>
  </channel>
</rss>

