0

I export data from R to sas format with package haven. However, when I open my .sas7bdat data. It fails.

library(haven)
write_sas(M, "C:/Users/user/desktop/MERGED_data.sas7bdat")

I provide my data structure below:
str(M)

Here is the properties.
properties

I double click the data to open in sas, but it fails and provides the information.
error

Any suggestion?

Peter Chen
  • 1,464
  • 3
  • 21
  • 48
  • Can you try passing `as.data.frame(M)` – pogibas Aug 26 '18 at 23:48
  • this is `data.table` and `data.frame` classes. – Peter Chen Aug 26 '18 at 23:52
  • 1
    Unlike the excellent `read_sas` counterpart, `write_sas` is still a bit limited in my experience. I haven't got it to work with anything beyond a very basic example yet - there is an open Github issue trying to route around this, but the `sas7bdat` format seems difficult to parse. https://github.com/tidyverse/haven/issues/224 – thelatemail Aug 27 '18 at 02:20
  • 1
    `write_sas` is not very reliable yet. The most reliable way I found to get datasets from R to SAS is writing them to an sqlite file and reading them via DBI in SAS. The package `foreign` also privoides good R to SAS export but is very slow. (Files are converted to CSV and a SAS-script to read the CSV is produced.) – snaut Aug 27 '18 at 07:21
  • Are you using Unix or Windows version of SAS? SAS datasets cannot use uppercase letters in the membername on unix, but I would expect a different error if that was the issue. – Tom Aug 27 '18 at 14:26
  • @Tom Windows. It's weird. – Peter Chen Aug 29 '18 at 02:32
  • Did you try generating a SAS XPORT format file instead? That should work better since the format is published. You might need to limit your variable names to 8 characters and string values to max 200 characters. – Tom Aug 29 '18 at 13:23

0 Answers0