<?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: Date Time Subset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-Time-Subset/m-p/782076#M249303</link>
    <description>&lt;P&gt;Assuming you have SAS dates/times and your variables are times it's fairly straightforward:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where timeVariable &amp;lt; '00:01:00't and  timepart(secondDateTimeVariable) between '00:01:00't and '04:00;00't;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Key concepts:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use TIMEPART() to get the time portion of a datetime variable&lt;/LI&gt;
&lt;LI&gt;Specify time as 'HH:MM:SS't&lt;/LI&gt;
&lt;LI&gt;FYI - If you use a WHERE statement you can use BETWEEN. If you use an IF statement, then you cannot use BETWEEN and need to structure that condition more similar to the first condition.&lt;/LI&gt;
&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338824"&gt;@gstover&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to figure out the syntax to subset a dataset based on the date and time.&amp;nbsp; First to grab all records that are prior to 12:01 a.m.&amp;nbsp; Then within these records query another date variable for the date and time between 12:01 am and 4:00 am.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Nov 2021 21:13:17 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-11-23T21:13:17Z</dc:date>
    <item>
      <title>Date Time Subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Time-Subset/m-p/782068#M249301</link>
      <description>&lt;P&gt;I am trying to figure out the syntax to subset a dataset based on the date and time.&amp;nbsp; First to grab all records that are prior to 12:01 a.m.&amp;nbsp; Then within these records query another date variable for the date and time between 12:01 am and 4:00 am.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 20:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Time-Subset/m-p/782068#M249301</guid>
      <dc:creator>gstover</dc:creator>
      <dc:date>2021-11-23T20:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Date Time Subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Time-Subset/m-p/782076#M249303</link>
      <description>&lt;P&gt;Assuming you have SAS dates/times and your variables are times it's fairly straightforward:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where timeVariable &amp;lt; '00:01:00't and  timepart(secondDateTimeVariable) between '00:01:00't and '04:00;00't;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Key concepts:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use TIMEPART() to get the time portion of a datetime variable&lt;/LI&gt;
&lt;LI&gt;Specify time as 'HH:MM:SS't&lt;/LI&gt;
&lt;LI&gt;FYI - If you use a WHERE statement you can use BETWEEN. If you use an IF statement, then you cannot use BETWEEN and need to structure that condition more similar to the first condition.&lt;/LI&gt;
&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/338824"&gt;@gstover&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to figure out the syntax to subset a dataset based on the date and time.&amp;nbsp; First to grab all records that are prior to 12:01 a.m.&amp;nbsp; Then within these records query another date variable for the date and time between 12:01 am and 4:00 am.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Nov 2021 21:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Time-Subset/m-p/782076#M249303</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-23T21:13:17Z</dc:date>
    </item>
  </channel>
</rss>

