dbosak01/libr

lib_load sas7bdat file date format

Closed this issue · 3 comments

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.

OK, let me look at it.

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.

@dbosak01 Thanks! specs function can solve the format problem.
I also use read_sas(path) function from haven package, it seems that the date format is correct.