From uhkeller at web.de  Thu Jun  1 13:31:26 2006
From: uhkeller at web.de (uhkeller at web.de)
Date: Thu,  1 Jun 2006 13:31:26 +0200 (CEST)
Subject: [Rd] write.foreign (SPSS) does not handle NAs properly (PR#8927)
Message-ID: <20060601113126.9ABA829D3C@slim.kubism.ku.dk>

Full_Name: Ulrich Keller
Version: 2.3.0 Patched (2006-04-28 r37936)
OS: Windows XP SP2
Submission from: (NULL) (158.64.77.43)


write.foreign(x,...,package="SPSS") writes incorrect data files if x contains
NAs. Missing values are represented as "NA" in the file; SPSS will print an
error every time it encounters an "NA". For example:

<CODE>
> x<-data.frame(v1=c(1,NA))
> library(foreign)
> write.foreign(x,stdout(),stdout(),package="SPSS")
1
NA
DATA LIST FILE= "1"  free
/ v1  .

VARIABLE LABELS
v1 "v1" 
 .

EXECUTE.
</CODE>

The first two lines after the call to write.foreign are the contents of the text
data file that is written. The "NA" should not be there and would make SPSS
generate an error.
One solution would be to use commas instead of blanks as delimiters and "" or "
" for NAs. The DATA LIST command would then be
DATA LIST FILE=filename FREE (",")



[Rd] write.foreign (SPSS) does not handle NAs properly (PR#8927)
uhkeller at web.de