0
votes

I used the write.foreign command from the foreign library to import R data to SPSS, I have used the following code but fail:

write.foreign(esoph,"esoph.dat","esoph.sps",package="SPSS")

But when I try to run the esoph.sps file in SPSS, the output gives me the following message is SPSS output:

DATA LIST FILE= "esoph.dat"  free (",") 
/ agegp alcgp tobgp ncases ncontrls  . 

>Error # 31 in column 17.  Text: esoph.dat 
>File not found. 
>This command not executed. 
VARIABLE LABELS

Can anyone tell me what happen? Thanks.

1
Remember : We are not able to look at the content of your files. - IRTFM
the esoph dataset is provided in R, I just followed and manual, but still can't get the result - lokheart
What does list.files(pattern = "esoph") give if you run it immediately after the write.foreign call? If the files are in the working directory, is SPSS looking for the files in the correct directory. The error suggests it couldn't find your files, so start with making sure you know where SPSS is looking for them, and that they are in that place. - Gavin Simpson
Give the write.foreign() the full paths to both files. Then the syntax should run smoothly. Except if you have commas in your character data. Or Umlauts. Or long strings.... - BurninLeo

1 Answers

1
votes

The file is probably not in the SPSS working directory. With show directory. SPSS shows the current working directory. Try editing the .sps file to include the full path in the FILE="esoph.dat" statement. Alternatively, try putting the .dat and .sps files in the working directory.