<?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 How to calculate the number of hours in a day? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546933#M151508</link>
    <description>&lt;P&gt;Every year, there is a day that has 23 hours, and a day has 25 hours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I am expecting to get the results like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hour=24 hourshortday=23 hourlongday=25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But actually, all hours are 24:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hour=24 hourshortday=24 hourlongday=24&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get the results I expected?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
hour=intck('hour','28MAR2019:00:00:00'dt,'29MAR2019:00:00:00'dt);
hourshortday=intck('hour','10MAR2019:00:00:00'dt,'11MAR2019:00:00:00'dt);
hourlongday=intck('hour','4NOV2018:00:00:00'dt,'5NOV2018:00:00:00'dt);
put (hour hourshortday hourlongday) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Mar 2019 15:56:36 GMT</pubDate>
    <dc:creator>jjjch</dc:creator>
    <dc:date>2019-03-28T15:56:36Z</dc:date>
    <item>
      <title>How to calculate the number of hours in a day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546933#M151508</link>
      <description>&lt;P&gt;Every year, there is a day that has 23 hours, and a day has 25 hours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I am expecting to get the results like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hour=24 hourshortday=23 hourlongday=25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But actually, all hours are 24:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hour=24 hourshortday=24 hourlongday=24&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get the results I expected?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
hour=intck('hour','28MAR2019:00:00:00'dt,'29MAR2019:00:00:00'dt);
hourshortday=intck('hour','10MAR2019:00:00:00'dt,'11MAR2019:00:00:00'dt);
hourlongday=intck('hour','4NOV2018:00:00:00'dt,'5NOV2018:00:00:00'dt);
put (hour hourshortday hourlongday) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 15:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546933#M151508</guid>
      <dc:creator>jjjch</dc:creator>
      <dc:date>2019-03-28T15:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the number of hours in a day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546937#M151509</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/110541"&gt;@jjjch&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Every year, there is a day that has 23 hours, and a day has 25 hours.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In what universe is your planet Earth?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may have a data system that has some notion that abuses date/time values. I have seen that working with data loggers that had hours 0 through 24 for every day (25 time points).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that you will have to provide examples from your actual data file that exhibits the behavior you show, including the dates with differing numbers of hours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS uses the rules for leap years where accumulated differences are applied by adding (or not) a leap day for date calculations and does not try to keep track of actual daily sidereal time.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 16:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546937#M151509</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-28T16:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the number of hours in a day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546940#M151510</link>
      <description>&lt;P&gt;Sorry, I should be more specific: I am living in Texas and we (and many other states in the US) have daylight saving time.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 16:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546940#M151510</guid>
      <dc:creator>jjjch</dc:creator>
      <dc:date>2019-03-28T16:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the number of hours in a day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546944#M151511</link>
      <description>&lt;P&gt;Hint: never use daylight savings time for real data if at all possible because of the DST&amp;nbsp;issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2010/11/24/calculating-the-utc-offset-in-your-sas-session/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2010/11/24/calculating-the-utc-offset-in-your-sas-session/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2012/03/08/using-sas-to-compute-the-onset-of-daylight-saving-time/" target="_blank"&gt;https://blogs.sas.com/content/iml/2012/03/08/using-sas-to-compute-the-onset-of-daylight-saving-time/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 16:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/546944#M151511</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-28T16:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the number of hours in a day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/550005#M152681</link>
      <description>&lt;P&gt;ballardw, thank you for your help. I ended up with writing a function like below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*define the function*/
libname myfunc "...";
proc fcmp outlib=myfunc.util.datetime;
	function hoursInADay(myDate);
		if missing(myDate) then return(.);
		jg_t_year = year(myDate);
		jg_t_shortday = nwkdom(2, 1, 3, jg_t_year);
		jg_t_longday = nwkdom(1, 1, 11, jg_t_year);
		if myDate=jg_t_shortday then jg_num_of_hours=23;
		else if myDate=jg_t_longday then jg_num_of_hours=25;
		else jg_num_of_hours=24;
		return(jg_num_of_hours);
	endsub;
run;


/*test the function*/
libname myfunc "...";
options cmplib=myfunc.util;

data _NULL_;
	array myDates{3} _temporary_ ('28MAR2019'd, '10MAR2019'd, '4NOV2018'd);
	do i=1 to dim(myDates);	
		hours = hoursInADay(myDates{i});
		put myDates{i}=yymmdd10.;
		put hours=/;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And the results are what I expected:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;myDates[1]=2019-03-28&lt;BR /&gt;hours=24&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myDates[2]=2019-03-10&lt;BR /&gt;hours=23&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myDates[3]=2018-11-04&lt;BR /&gt;hours=25&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 10 Apr 2019 16:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-the-number-of-hours-in-a-day/m-p/550005#M152681</guid>
      <dc:creator>jjjch</dc:creator>
      <dc:date>2019-04-10T16:25:37Z</dc:date>
    </item>
  </channel>
</rss>

