rsasdataset

Can anyone help me write a R data frame as a SAS data set?


In R, I have used the write.foreign() function from the foreign library in order to write a data frame as a SAS data set.

write.foreign(df = test.df, datafile = 'test.sas7bdat', codefile = 'test.txt', package = "SAS")

The SAS data file is written, but when I try to open it in SAS Viewer 9.1 (Windows XP), I receive the following message - "SAS Data set file format is not supported".

Note: I am generally unfamiliar with SAS, so if an answer exists that would have been known by a regular SAS user, please excuse my ignorance.


Solution

  • I'm not much of a SAS user either, but I've used write.xport() before and it's worked fine. My crude understanding is that there are two types of SAS files, internal ones and XPORT files. The XPORT ones are the ones that are more compatible across different versions, architectures, etc.