Patrick McCormick
2011-Sep-16 19:15 UTC
[Rd] patch] writeForeignSAS writes invalid SASdata for logical columns
Hi, 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. Example: 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: 1,TRUE 2,FALSE 3,TRUE 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. Thanks, Patrick McCormick