-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dates are not correctly derived (SAS vs R) #142
Comments
@adchan11 Do you know which specific xportr function is causing the issue? When I run only xportr_write, the conversion from R to SAS date is correctly handled by haven.
|
After reviewing the screenshot of your R df, it appears that the variable's type might not being recognized as a date and is therefore not being correctly converted. I think it is crucial to ensure accurate conversion of dates. We should verify that numeric date, time, and datetime values, variables ending with -DT, -TM, or -DTM, have the correct R type (if it is the cause of the issue) for successful conversion. Thank you for highlighting this issue. |
Thanks @cpiraux. Here's example R code which demonstrates the issue:
you can see the differences of the final Note adsl_original is mock data of a dataset that I have internally. |
Thanks for taking a look into this. I thought dates and datetimes are supposed to be numeric in SAS: so shouldn't RFICDT and RFICDTM supposed to be coerced to numeric in order to apply the formats of Date9. and Datetime20.? |
Thank you both for the examples and discussion.
metacore <- data.frame(
dataset = "test",
variable = c("SUBJID", "CHARCTER", "CHAR", "TEXT", "DATE", "INTEGER", "CHAR2DT", "POSIXct2DT"),
type = c("numeric", "character", "char", "text", "date", "integer", "date", "date"),
format = c(NA, "yymmdd10.",NA, NA, NA, NA, NA, NA)
)
.df <- tibble(
SUBJID = c("1", "2", "3"),
CHARCTER = as.Date(0:2, origin = "1960-01-01"),
CHAR = as.Date(0:2, origin = "1960-01-01"),
TEXT = as.Date(0:2, origin = "1960-01-01"),
DATE = as.Date(0:2, origin = "1960-01-01"),
INTEGER = as.Date(0:2, origin = "1960-01-01"),
CHAR2DT = "1960-01-01",
POSIXct2DT = as.POSIXct("1960-01-01")
) |
I added some feedback:
Specs file might not follow the define xml data type. Some post-processing between specs and final define.xml are possible. I suggest keeping numeric and character in Type to avoid being too restrictive.
Date type in metadata is character type in SAS. Date type is use for --DTC SDTM variables. More information can be found in CDISC Define-XML Specification Version 2.1 page 29.
Per CDISC ADaM IG v1.2, variables with numeric date, datetime or time should have the following suffix, -- DT, --DTM or –TM. They should also be formatted to be human-readable. The numeric dates have an integer/numeric metadata type and should have the format populated. |
I would like to see more diagrams like this in |
Closes #142 issue_142_updated to account for DT, DTM, TM variables
What happened?
In R,
but in SAS:
Sources:
https://support.sas.com/publishing/pubcat/chaps/59411.pdf
https://bookdown.org/rdpeng/rprogdatascience/dates-and-times.html
Therefore, we see a 10 year difference in dates after running the xportr functions:
Session Information
No response
Reproducible Example
No response
The text was updated successfully, but these errors were encountered: