From patrick.mccormick at alum.mit.edu  Fri Sep 16 21:15:43 2011
From: patrick.mccormick at alum.mit.edu (Patrick McCormick)
Date: Fri, 16 Sep 2011 15:15:43 -0400
Subject: [Rd] patch] writeForeignSAS writes invalid SASdata for logical
	columns
Message-ID: <CAEut_u5JLK-r8n0J5vfgW3g0H++jQODm1bpkkEWJnhSZvwKuAQ@mail.gmail.com>

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


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