- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Every year, there is a day that has 23 hours, and a day has 25 hours.
So I am expecting to get the results like below:
hour=24 hourshortday=23 hourlongday=25
But actually, all hours are 24:
hour=24 hourshortday=24 hourlongday=24
How can I get the results I expected?
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@jjjch wrote:
Every year, there is a day that has 23 hours, and a day has 25 hours.
In what universe is your planet Earth?
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).
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I should be more specific: I am living in Texas and we (and many other states in the US) have daylight saving time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hint: never use daylight savings time for real data if at all possible because of the DST issues.
https://blogs.sas.com/content/sasdummy/2010/11/24/calculating-the-utc-offset-in-your-sas-session/
https://blogs.sas.com/content/iml/2012/03/08/using-sas-to-compute-the-onset-of-daylight-saving-time/
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
ballardw, thank you for your help. I ended up with writing a function like below.
/*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;
And the results are what I expected:
myDates[1]=2019-03-28
hours=24
myDates[2]=2019-03-10
hours=23
myDates[3]=2018-11-04
hours=25