<?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: Change all time variables to nearest hour in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405503#M26064</link>
    <description>&lt;P&gt;Since SAS time and datetime values are counts of seconds, this will also work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;timevar = int(timevar/3600) * 3600;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Oct 2017 12:42:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-19T12:42:06Z</dc:date>
    <item>
      <title>Change all time variables to nearest hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405486#M26061</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've a number of time variables in the following example&amp;nbsp;time8. format; 17:34:34, 09:07:00.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to do is change them all to the nearest hour i.e. 17:00:00 and 09:00:00.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to do this in an array similar to how you would do it for month variables e.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array datevars {*} intdate1  previntdate;
do i=1 to dim(datevars);
datevars{i} = intnx('month',datevars{i},0,'begin');
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help is most welcome.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 12:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405486#M26061</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-10-19T12:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Change all time variables to nearest hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405489#M26062</link>
      <description>&lt;P&gt;From your example, it looks like you want to "round down" to the hour the value is in, not necessarily the "nearest" hour boundary, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 x = intnx('hour', '05FEB2010:17:34:43'dt, 0, 'b'); 
 y = intnx('hour', '17:34:43't, 0, 'b');
 format x datetime20. y time8.;
 put x= y=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;x=05FEB2010:17:00:00 y=17:00:00&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Oct 2017 12:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405489#M26062</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-10-19T12:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Change all time variables to nearest hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405499#M26063</link>
      <description>&lt;P&gt;Or maybe simpler:&lt;/P&gt;
&lt;PRE&gt;want=hour(timevar) * (60 * 60);
&lt;/PRE&gt;
&lt;P&gt;I.e. take the hour and multiple it by minutes and seconds to get a time value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it time variables you are dealing with or dates, as your question about time values does not match the example which uses date variables?&amp;nbsp; If its just time then:&lt;/P&gt;
&lt;PRE&gt;want=input(cats(put(hour(timevar),z2.),":00:00"),tod11.);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just chops off the min/sec and adds 00 again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 12:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405499#M26063</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-19T12:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Change all time variables to nearest hour</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405503#M26064</link>
      <description>&lt;P&gt;Since SAS time and datetime values are counts of seconds, this will also work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;timevar = int(timevar/3600) * 3600;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Oct 2017 12:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-time-variables-to-nearest-hour/m-p/405503#M26064</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-19T12:42:06Z</dc:date>
    </item>
  </channel>
</rss>

