[Rd] patch] writeForeignSAS writes invalid SASdata for logical columns

From: Patrick McCormick <patrick.mccormick_at_alum.mit.edu>
Date: Fri, 16 Sep 2011 15:15:43 -0400


I have been trying to encourage R use among my colleagues who use SAS, and part of that is demonstrating that R can perform a high fidelity export to SAS with the foreign package.  Recently one of my exports caused a SAS error, and I found that logical vectors within a dataframe are not exported properly.  While write.foreign doesn't claim to handle this datatype, I think it is pretty essential (and easy) to export.

I searched and have not found this issue reported before.

df = data.frame(id = c(1,2,3), boolean = c(TRUE,FALSE,TRUE)) library(foreign)
write.foreign(df, "test.sasdata", "test.sas",    "SAS", dataname="WORK.TEST", validvarname="V7")

Contents of test.sasdata:


SAS output:
NOTE: Invalid data for boolean in line 1 3-6 RULE: ----+----1--...
1     1,TRUE 6
id=1 boolean=. _ERROR_=1 _N_=1
... (errors for remaining rows)

Attached is a patch to foreign which I believe will address the issue by converting logical vectors into integers (0,1).  I have not tested it very much.

Patrick McCormick

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 16 Sep 2011 - 19:31:22 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 18 Sep 2011 - 10:40:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive