<?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 add hours to a time value to get a new time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860369#M339890</link>
    <description>&lt;P&gt;Time values in SAS are counts of seconds, so you need to expand your hours to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new = so + (half * 3600);
format new time5.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The brackets are just there for clarification, mathematically they're not needed (multiplication is done before addition).&lt;/P&gt;</description>
    <pubDate>Thu, 23 Feb 2023 06:51:53 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-02-23T06:51:53Z</dc:date>
    <item>
      <title>How to add hours to a time value to get a new time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860366#M339888</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a dataset that need to calculate a new time. For example, I slept at 00:00 (so) and slept for 6.5 (half) hours, so I got up at 06:00 (new).&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;so (hh:mm)&lt;/TD&gt;&lt;TD&gt;half (hrs)&lt;/TD&gt;&lt;TD&gt;new (hh:mm)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;1:30&lt;/TD&gt;&lt;TD&gt;3.32&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;TD&gt;1:00&lt;/TD&gt;&lt;TD&gt;3.73&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;31&lt;/TD&gt;&lt;TD&gt;0:00&lt;/TD&gt;&lt;TD&gt;3.94&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;68&lt;/TD&gt;&lt;TD&gt;3:00&lt;/TD&gt;&lt;TD&gt;3.32&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;87&lt;/TD&gt;&lt;TD&gt;0:50&lt;/TD&gt;&lt;TD&gt;3.23&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I calculate the "new" variable?&lt;/P&gt;&lt;P&gt;I tried simply to add " so+half" then I got seconds.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 06:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860366#M339888</guid>
      <dc:creator>Vergriffenego</dc:creator>
      <dc:date>2023-02-23T06:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to add hours to a time value to get a new time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860369#M339890</link>
      <description>&lt;P&gt;Time values in SAS are counts of seconds, so you need to expand your hours to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new = so + (half * 3600);
format new time5.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The brackets are just there for clarification, mathematically they're not needed (multiplication is done before addition).&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 06:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860369#M339890</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-23T06:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to add hours to a time value to get a new time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860371#M339892</link>
      <description>&lt;P&gt;Assuming your input data looks like this (it is better to present is as a data step):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;                                                                                                                              
input id so : time. half;                                                                                                               
format so time5.;                                                                                                                       
cards;                                                                                                                                  
7      1:30      3.32                                                                                                                   
26      1:00      3.73                                                                                                                  
31      0:00      3.94                                                                                                                  
68      3:00      3.32                                                                                                                  
87      0:50      3.23                                                                                                                  
;run;   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can simply convert the hours to seconds (60*60=3600 seconds/hour) and add to get the new time:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  set have;                                                                                                                             
  new=so+half*3600;                                                                                                                     
  format new time5.;                                                                                                                    
run;   
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Feb 2023 07:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860371#M339892</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-23T07:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to add hours to a time value to get a new time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860372#M339893</link>
      <description>&lt;P&gt;&amp;nbsp;This worked. Thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 07:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860372#M339893</guid>
      <dc:creator>Vergriffenego</dc:creator>
      <dc:date>2023-02-23T07:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to add hours to a time value to get a new time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860373#M339894</link>
      <description>&lt;P&gt;Thank you for your reply! The solution worked well!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 07:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-hours-to-a-time-value-to-get-a-new-time/m-p/860373#M339894</guid>
      <dc:creator>Vergriffenego</dc:creator>
      <dc:date>2023-02-23T07:19:22Z</dc:date>
    </item>
  </channel>
</rss>

