Skip to content
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

Date and datetime columns become numeric on round-trip #22

Open
warnes opened this issue Dec 30, 2020 · 0 comments
Open

Date and datetime columns become numeric on round-trip #22

warnes opened this issue Dec 30, 2020 · 0 comments
Assignees

Comments

@warnes
Copy link
Member

warnes commented Dec 30, 2020

Date and datetime columns written using write.xport and read back in using read.xport are losing the date and time type information:

Running tests/testDates.R yields:

> library(SASxport)

> Sys.setenv("TZ"="GMT")

> ## Create a small data set containing dates, times, and date-times
> 
> dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")

> times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26")

> temp <- data.frame(
+   x=c(1, 2, 3, 4, 5 ),
+   y=c('a', 'B', 'c', 'd', 'e' ),
+   dates=strptime(dates, "%m/%d/%y"),
+   datetimes=strptime( paste .... [TRUNCATED] 

> print(temp)
  x y      dates           datetimes
1 1 a 1992-02-27 1992-02-27 23:03:20
2 2 B 1992-02-27 1992-02-27 22:29:56
3 3 c 1992-01-14 1992-01-14 01:03:30
4 4 d 1992-02-28 1992-02-28 18:21:03
5 5 e 1992-02-01 1992-02-01 16:56:26

> write.xport( DATETIME=temp, file="datetime.xpt")

> temp2 <- read.xport(file="datetime.xpt", names.tolower=FALSE)

> #! FIXME: Date and datetime are coming back as numeric
> print(temp2)
  X Y      DATES   DATETIME
1 1 a 1014768000 1014851000
2 2 B 1014768000 1014848996
3 3 c 1010966400 1010970210
4 4 d 1014854400 1014920463
5 5 e 1012521600 1012582586

> identical(temp, temp2)
[1] FALSE

> # Test for issue #19: toSAS() - The number of seconds since
> # 1960-01-01:00:00:00 GMT is greater than it is supposed to be
> 
> zeroDate <- ISOdat .... [TRUNCATED] 

> zeroSAS <- toSAS(zeroDate, format="DATETIME19.")

> stopifnot(zeroSAS==0)
@warnes warnes self-assigned this Dec 30, 2020
warnes added a commit to elimillera/SASxport that referenced this issue Dec 30, 2020
* Don't assign empty ("" or " ") labels to datasets
* Use auto-detected SAS attributes unless  user has specified them.
* `testDates.R` now does an explicit compare to detect regressions like r-gregmisc#22.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant