guzu92 guzu92 - 1 year ago 119
R Question

SAS to R datetime conversion

SAS documentation states the following for data and datetime values:

SAS time value: is a value representing the number of seconds since midnight of the current day. SAS time values are between 0 and 86400.

SAS datetime value: is a value representing the number of seconds between January 1, 1960 and an hour/minute/second within a specified date.

I'm willing to convert the following date and hour values with R, I have a big doubt for the hour (datetime) conversion, which one of the "HH:MM:SS" values within

is correct ?

I have to separate columns, SAS date = 20562 and SAS hour = 143659, in my table

R: R_date <- as.Date(as.integer(20562), origin="1960-01-01"); R_date
[1] "2016-04-18"

R: R_hour1 <- as.POSIXct(143659, origin = R_date); R_hour1
[1] "2016-04-19 17:54:19 CEST"

R: R_hour2 <- as.POSIXct(143659, origin = "1960-01-01"); R_hour2
[1] "1960-01-02 16:54:19 CET"

Joe Joe
Answer Source

Similar to R, SAS Date and DateTime values can have whatever origin you wish them to. The default formats have a default (1/1/1960 for both), but you can use the datetime field to mean any origin you wish, and it will generally still work perfectly well with any of the datetime functions (though it will not display properly unless you write a custom format). It is very possible to have a different origin, as you show above with R_hour1.

As such, you would have to ask the person who generated the data what the meaning of the field is and what its origin should be.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download