<?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: Time  duration in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Time-duration/m-p/485352#M129556</link>
    <description>&lt;P&gt;Maxim 3: read the log. Your code contains several severe syntax errors (blank between time literal and the t, missing brackets, intx instead of intnx, missing arguments to intnx function).&lt;/P&gt;
&lt;P&gt;Run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table;
input opendate datetime22.;
format opendate datetime22.;
cards;
09aug2018:22:10:00
09aug2018:21:50:00
;
run;

data table_new;
set table;
if timepart(opendate) =&amp;gt; '22:00't
then starttime = dhms(datepart(intnx('dtday',starttime,1)),8,0,0);
else starttime = opendate;
format starttime datetime20.;
run&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Correction: The code needs to care for hours before 08:00, also:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_new;
set table;
if timepart(opendate) =&amp;gt; '22:00't
then starttime = dhms(datepart(intnx('dtday',opendate,1)),8,0,0);
else starttime = max(opendate,dhms(datepart(intnx('dtday',opendate,0)),8,0,0));
format starttime datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117620"&gt;@Gil_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have a data set that changes start time to 8 am if its after hours.&lt;BR /&gt;Data table;&lt;BR /&gt;Set table;&lt;BR /&gt;Starttime=opendate;&lt;BR /&gt;If timepart(starttime)=&amp;gt;^22:00' t then starttime=dhms(datepart(INTX'dtday', 1,),8,0,0) ;&lt;BR /&gt;Format starttime datetime20.;run;&lt;BR /&gt;&lt;BR /&gt;I need the time to go from=&amp;gt; '22:00. Thru =&amp;lt;08:00 next morning.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Thu, 09 Aug 2018 08:44:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-08-09T08:44:06Z</dc:date>
    <item>
      <title>Time  duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-duration/m-p/485342#M129555</link>
      <description>I have a data set that changes start time to 8 am if its after hours.&lt;BR /&gt;Data table;&lt;BR /&gt;Set table;&lt;BR /&gt;Starttime=opendate;&lt;BR /&gt;If timepart(starttime)=&amp;gt;^22:00' t then starttime=dhms(datepart(INTX'dtday', 1,),8,0,0) ;&lt;BR /&gt;Format starttime datetime20.;run;&lt;BR /&gt;&lt;BR /&gt;I need the time to go from=&amp;gt; '22:00. Thru =&amp;lt;08:00 next morning.&lt;BR /&gt;</description>
      <pubDate>Thu, 09 Aug 2018 04:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-duration/m-p/485342#M129555</guid>
      <dc:creator>Gil_</dc:creator>
      <dc:date>2018-08-09T04:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Time  duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-duration/m-p/485352#M129556</link>
      <description>&lt;P&gt;Maxim 3: read the log. Your code contains several severe syntax errors (blank between time literal and the t, missing brackets, intx instead of intnx, missing arguments to intnx function).&lt;/P&gt;
&lt;P&gt;Run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table;
input opendate datetime22.;
format opendate datetime22.;
cards;
09aug2018:22:10:00
09aug2018:21:50:00
;
run;

data table_new;
set table;
if timepart(opendate) =&amp;gt; '22:00't
then starttime = dhms(datepart(intnx('dtday',starttime,1)),8,0,0);
else starttime = opendate;
format starttime datetime20.;
run&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Correction: The code needs to care for hours before 08:00, also:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_new;
set table;
if timepart(opendate) =&amp;gt; '22:00't
then starttime = dhms(datepart(intnx('dtday',opendate,1)),8,0,0);
else starttime = max(opendate,dhms(datepart(intnx('dtday',opendate,0)),8,0,0));
format starttime datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117620"&gt;@Gil_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have a data set that changes start time to 8 am if its after hours.&lt;BR /&gt;Data table;&lt;BR /&gt;Set table;&lt;BR /&gt;Starttime=opendate;&lt;BR /&gt;If timepart(starttime)=&amp;gt;^22:00' t then starttime=dhms(datepart(INTX'dtday', 1,),8,0,0) ;&lt;BR /&gt;Format starttime datetime20.;run;&lt;BR /&gt;&lt;BR /&gt;I need the time to go from=&amp;gt; '22:00. Thru =&amp;lt;08:00 next morning.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 09 Aug 2018 08:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-duration/m-p/485352#M129556</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-09T08:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Time  duration</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-duration/m-p/485371#M129557</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117620"&gt;@Gil_&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;If I understand right what you're after then below code should do the job.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input dttm datetime.;
  format dttm datetime21.;
  datalines;
08Aug2016 21:59:59
08Aug2016 22:00:00
08Aug2016 22:00:01
08Aug2016 23:59:59
09Aug2016 00:00:00
09Aug2016 00:00:01
09Aug2016 07:59:59
09Aug2016 08:00:00
09Aug2016 08:00:01
;
run;

data want;
  set have;
  format dttm_work datetime21.;
  dttm_work=ifn(hour(intnx('dthour',dttm,2,'s'))&amp;lt;10, 
                intnx('dthour',intnx('dtday',intnx('dthour',dttm,2,'s'),0,'b'),8,'s'), 
                dttm
                );
run;
proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Aug 2018 08:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-duration/m-p/485371#M129557</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-08-09T08:31:38Z</dc:date>
    </item>
  </channel>
</rss>

