Skip to content

How to this SAS transport file in R?

4 messages · zhiji19, Brian Ripley, David Freedman +1 more

#
Dear All, 

I try to read the SAS transport file in R, but it shows error. Please help!
I am using R 2.11.1 

library(foreign) 
download.file("http://isites.harvard.edu/fs/docs/icb.topic35387.files/demo_c.xpt","C:/Desktop/demo_c.xpt") 
sasxport <- read.xport("C:/Desktop/demo_c.xpt") 

Error in lookup.xport(file) : file not in SAS transfer format
#
You didn't tell us your OS.  That is a binary file, and from 
?download.file:

     mode: character.  The mode with which to write the file. Useful
           values are ?"w"?, ?"wb"? (binary), ?"a"? (append) and ?"ab"?.
           Only used for the ?"internal"? method.

Only on Windows are the binary modes different, so it looks like you
forgot mode="wb".
On Sun, 5 Dec 2010, someone ashamed of her real name wrote:

            
[...]
Yes, that does mean you.
#
I've had good success with the read.xport function in the SASxport (not
foreign) package.  But couldn't you just use something like

mydata<-read.xport('http..../demo_c.xpt')

The transport file looks like it's one of the NHANES demographic files.
#
I think You need to use mode='wb' in your download statement

download.file("http://isites.harvard.edu/fs/docs/icb.topic35387.files/demo_c.xpt",
              "C:/Desktop/demo_c.xpt", mode='wb')

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204