lib_load sas7bdat file date format
Closed this issue · 3 comments
akarito commented
When I load sas7bdat file using lib_load, the format of date was numeric,it is hard to re-format the date as format like yymmdd10. in sas.
dbosak01 commented
OK, let me look at it.
dbosak01 commented
I remember now. This is a problem with the underlying haven package. In SAS the date column is a numeric column with a format. But R can't understand those format names. So you have to explicitly tell the libname function which columns are dates. Like this:
library(libr)
# Create import spec and specify date data type for each column known to be a date
spcs <- specs(abc_adam_adlb = import_spec(TRTSDT = "date"))
# Pass import spec to libname
libname(dat, "c:/packages/Testing/data", "sas7bdat", import_spec = spcs )
# Load library
lib_load(dat)
# View dictionary to see data types
View(dictionary(dat.abc_adam_adlb))
Reminder that all dataset and column names are case-sensitive. If you can't get it, upload your dataset and I'll send you back some code to read it.