<?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 Hour is next largest hour when extracting hour from datetime in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11247#M1272</link>
    <description>I have a datetime from which I would like to extract hour in a new column in the data set. For datetime values greater than 30minutes past the hour, the hour is reported as the next largest hour. Why is this happening and how do I fix it? Below is my code and the resulting output. NOTE: I also used &lt;I&gt;time=timepart(timestamp); format time hour.;&lt;/I&gt; with the same result. &lt;BR /&gt;
&lt;BR /&gt;
Tiffanie&lt;BR /&gt;
&lt;BR /&gt;
data hours;&lt;BR /&gt;
  set periods;&lt;BR /&gt;
  hour=timepart(timestamp);&lt;BR /&gt;
  format hour hour. ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
timestamp, hour&lt;BR /&gt;
01MAY2010:15:45:00, 16&lt;BR /&gt;
01MAY2010:16:16:00, 16&lt;BR /&gt;
01MAY2010:16:38:00, 17</description>
    <pubDate>Wed, 16 Feb 2011 17:28:02 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2011-02-16T17:28:02Z</dc:date>
    <item>
      <title>Hour is next largest hour when extracting hour from datetime</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11247#M1272</link>
      <description>I have a datetime from which I would like to extract hour in a new column in the data set. For datetime values greater than 30minutes past the hour, the hour is reported as the next largest hour. Why is this happening and how do I fix it? Below is my code and the resulting output. NOTE: I also used &lt;I&gt;time=timepart(timestamp); format time hour.;&lt;/I&gt; with the same result. &lt;BR /&gt;
&lt;BR /&gt;
Tiffanie&lt;BR /&gt;
&lt;BR /&gt;
data hours;&lt;BR /&gt;
  set periods;&lt;BR /&gt;
  hour=timepart(timestamp);&lt;BR /&gt;
  format hour hour. ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
timestamp, hour&lt;BR /&gt;
01MAY2010:15:45:00, 16&lt;BR /&gt;
01MAY2010:16:16:00, 16&lt;BR /&gt;
01MAY2010:16:38:00, 17</description>
      <pubDate>Wed, 16 Feb 2011 17:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11247#M1272</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-16T17:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Hour is next largest hour when extracting hour from datetime</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11248#M1273</link>
      <description>You have other options though you must consider the SAS DOC for HOUR format and the caveat note about "...rounding...".&lt;BR /&gt;
&lt;BR /&gt;
If not suitable, consider using the HOUR function to extract the hour-portion and display it separately.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
hour format site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
DOC reference below:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000198051.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000198051.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Excerpt below:&lt;BR /&gt;
Details &lt;BR /&gt;
&lt;BR /&gt;
SAS rounds hours based on the value of minutes in the SAS time value.&lt;BR /&gt;
&lt;BR /&gt;
The HOUR format uses asterisks to format values that are outside the time range 0-24 hours, such as datetime values.</description>
      <pubDate>Wed, 16 Feb 2011 17:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11248#M1273</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-02-16T17:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Hour is next largest hour when extracting hour from datetime</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11249#M1274</link>
      <description>since it rounding try&lt;BR /&gt;
hour= floor( mod( datetime_value, 3600 ) /3600 ) ;&lt;BR /&gt;
(datetime values are a number of seconds)</description>
      <pubDate>Thu, 17 Feb 2011 16:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11249#M1274</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-02-17T16:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hour is next largest hour when extracting hour from datetime</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11250#M1275</link>
      <description>Thank you, Scott. I failed to read the literature before posting. Here's how I fixed it:&lt;BR /&gt;
&lt;BR /&gt;
data hours;&lt;BR /&gt;
  set periods;&lt;BR /&gt;
  hour=hour(timestamp);&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 17 Feb 2011 21:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Hour-is-next-largest-hour-when-extracting-hour-from-datetime/m-p/11250#M1275</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-17T21:05:23Z</dc:date>
    </item>
  </channel>
</rss>

