<?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: How to deduct an hour from the TIME20.3 format? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732870#M228375</link>
    <description>&lt;P&gt;Internally SAS maintains time as number of seconds from midnight. So one hour is 3600 Seconds.&lt;BR /&gt;Subtracting 3600 gives the result.&lt;BR /&gt;Sample code is given below. Modify as needed&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_time;
informat time_ time12.3;
format time_ time12.3;
input time_;
datalines;
10:07:46.104   
12:00:16.100  
02:11:26.040  
;
run;
data test_time;
format new_time time12.3;
set test_time;
new_time=time_ - 3600;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output will be some thing like this.&lt;BR /&gt;Time_ is the original time and new_time is what we get substracting one hour (3600 secs)&lt;/P&gt;
&lt;TABLE class="table" aria-label="Data Set WORK.TEST_TIME"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;new_time&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;time_&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;9:07:46.104&lt;/TD&gt;
&lt;TD class="r data"&gt;10:07:46.104&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;11:00:16.100&lt;/TD&gt;
&lt;TD class="r data"&gt;12:00:16.100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;1:11:26.040&lt;/TD&gt;
&lt;TD class="r data"&gt;2:11:26.040&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Sun, 11 Apr 2021 15:51:10 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2021-04-11T15:51:10Z</dc:date>
    <item>
      <title>How to deduct an hour from the TIME20.3 format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732859#M228372</link>
      <description>&lt;P&gt;I need to deduct an hour from my Time variable. Currently, the variable is in TIME20.3 format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Time&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;10:07:46.104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and i need&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Time_new&lt;/P&gt;&lt;P&gt;9:07:46.104&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, i would like to create another time variable as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Time_new2&lt;/P&gt;&lt;P&gt;9:07:46.000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 15:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732859#M228372</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2021-04-11T15:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to deduct an hour from the TIME20.3 format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732869#M228374</link>
      <description>&lt;P&gt;Time values are stored as the number of seconds since midnight.&amp;nbsp; To to subtract one hour you need to subtract 60*60 seconds.&lt;/P&gt;
&lt;P&gt;It is easier to just use a time literal.&amp;nbsp; '01:00't is one hour.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  have = '10:07:46.104't ;
  want = have - '01:00't ;
  format have want time20.3 ;
  put have= want=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want to round the time to the newest second?&amp;nbsp; ROUND(want,1)&lt;/P&gt;
&lt;P&gt;Or truncate the fractional seconds? INT(want)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 15:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732869#M228374</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-11T15:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to deduct an hour from the TIME20.3 format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732870#M228375</link>
      <description>&lt;P&gt;Internally SAS maintains time as number of seconds from midnight. So one hour is 3600 Seconds.&lt;BR /&gt;Subtracting 3600 gives the result.&lt;BR /&gt;Sample code is given below. Modify as needed&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test_time;
informat time_ time12.3;
format time_ time12.3;
input time_;
datalines;
10:07:46.104   
12:00:16.100  
02:11:26.040  
;
run;
data test_time;
format new_time time12.3;
set test_time;
new_time=time_ - 3600;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output will be some thing like this.&lt;BR /&gt;Time_ is the original time and new_time is what we get substracting one hour (3600 secs)&lt;/P&gt;
&lt;TABLE class="table" aria-label="Data Set WORK.TEST_TIME"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;new_time&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;time_&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;9:07:46.104&lt;/TD&gt;
&lt;TD class="r data"&gt;10:07:46.104&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;11:00:16.100&lt;/TD&gt;
&lt;TD class="r data"&gt;12:00:16.100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;1:11:26.040&lt;/TD&gt;
&lt;TD class="r data"&gt;2:11:26.040&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sun, 11 Apr 2021 15:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732870#M228375</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-04-11T15:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to deduct an hour from the TIME20.3 format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732879#M228377</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As mentioned by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp;the format does not play a role w.r.t. your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use the INTNX function to get what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
 have = '10:07:46.104't ;
 Time_new  = INTNX('HOUR',have,-1,'SAME');
 put Time_new  TIME20.3;
 Time_new2 = INTNX('SECOND',have,-60*60,'BEGINNING');
 put Time_new2 TIME20.3;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 11 Apr 2021 16:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deduct-an-hour-from-the-TIME20-3-format/m-p/732879#M228377</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-04-11T16:10:39Z</dc:date>
    </item>
  </channel>
</rss>

