haven icon indicating copy to clipboard operation
haven copied to clipboard

Length, Type and other properties are missing when using haven::read_sas

Open dgyurko opened this issue 1 year ago • 2 comments

When reading any sas7bdat file via haven::read_sas, the only metadata property returned is the "Format".

pyreadstat, a python library that is also based on ReadStat has this feature

e.g.: the "Length" property is returned as variable_storage_width: a dict with keys being variable names and values being the storage width

# Download https://github.com/tidyverse/haven/blob/main/inst/examples/iris.sas7bdat

sas <- haven::read_sas(data_file = "iris.sas7bdat")
lapply(sas, attributes)

# Output
# $Sepal_Length
# $Sepal_Length$format.sas
# [1] "BEST"
# 
# 
# $Sepal_Width
# $Sepal_Width$format.sas
# [1] "BEST"
# 
# 
# $Petal_Length
# $Petal_Length$format.sas
# [1] "BEST"
# 
# 
# $Petal_Width
# $Petal_Width$format.sas
# [1] "BEST"
# 
# 
# $Species
# $Species$format.sas
# [1] "$"

Expected result: The SAS metadata properties: "Label", "Length", "Type", "Format", Informat returned as attributes for each column Actual result: Only "Format" is returned as an attribute

dgyurko avatar Mar 14 '23 11:03 dgyurko

Thanks for initiating this issue @dgyurko Similar for haven::read_xpt, the metadata properties are kept for class, format.sas, label, but not for length and type

kaz462 avatar Apr 14 '23 19:04 kaz462

This would be very nice update!! We use this in the xportrpackage - as the pharma industry has to deliver xpts to Health Authorities. :(

bms63 avatar Apr 14 '23 20:04 bms63