The problem posed by the user @spore234 appears to be solved: sas7bdat date format to R date format
I, too, uploaded a .sas7bdat
file, and I got numbers instead of dates. Unlike @spore234, the use of as.Date(..., origin = "1970-01-01")
is not correct but using `as.POSIXct(..., origin = "1970-01-01") gives the right date but not the right time. It is the reverse of the findings from 5 years ago.
To avoid confusion, I opened up a new issue.
dir <- tmpdir()
#The dates in SAS are
# SUBMITTED_AT RUN_DATE
# 06APR2021:16:17:02 11DEC2020:05:00:00
# 06APR2021:16:17:02 11DEC2020:05:00:00
wide <- sas7bdat::read.sas7bdat(paste0(dir, "\\sas7bdat_issue.sas7bdat"))
print(wide)
#> SUBMITTED_AT RUN_DATE
#> 1 1933345022 1923282000
#> 2 1933345022 1923282000
as.Date(wide$SUBMITTED_AT, origin = "1970-01-01")
#> [1] "5295288-11-18" "5295288-11-18"
# gives the wrong year, which is not correct. Using `as.POSIXct()` with no modification gives the right day but not the right time.
as.POSIXct(wide$SUBMITTED_AT,origin='1960-01-01')
#> [1] "2021-04-06 12:17:02 EDT" "2021-04-06 12:17:02 EDT"
It's an easy fix, as we can format not to show the time. However, could some numbers get lost in the SAS--R conversion?
as.POSIXct(wide$RUN_DATE, format = "%Y-%m-%d", origin='1960-01-01')
#> [1] "2020-12-11 EST" "2020-12-11 EST"
xfun::session_info("sas7bdat")
#> R version 4.0.4 (2021-02-15)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 18363)
#>
#> Locale:
#> LC_COLLATE=English_United States.1252
#> LC_CTYPE=English_United States.1252
#> LC_MONETARY=English_United States.1252
#> LC_NUMERIC=C
#> LC_TIME=English_United States.1252
#>
#> Package version:
#> sas7bdat_0.5
Created on 2021-05-11 by the reprex package (v1.0.0)
SAS (r) Proprietary Software 9.4 (TS1M4)
Huh? These findings are bizarre.