[R] Cannot read XPT file using foreign package

Daniel Nordlund djnordlund at frontier.com
Sat Oct 5 02:45:39 CEST 2013


There two different "transport" or "portable" file types that SAS creates: 1. using Proc CPORT
2. using the XPORT engine in a LIBNAME statement.

That may not mean much to a non-SAS user, but people often use 'xpt' as a file extension for both approaches.  If Proc CPORT was used to write the file, read.xport will not be able to read it.  read.xport only reads files written using the XPORT engine.

If you don't have access to SAS you will need to get whomever created the file to re-create it.  

Dan

Daniel Nordlund
Bothell, WA USA
 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Dennis Fisher
> Sent: Friday, October 04, 2013 5:01 PM
> To: Duncan Murdoch; r-help at stat.math.ethz.ch
> Subject: Re: [R] Cannot read XPT file using foreign package
> 
> Duncan
> 
> I looked at
> 	support.sas.com/techsup/technote/ts140.pdf
> and it is a bit difficult to decipher.  I then replaced the string "^@" in
> the file contents with "!".  There is some concordance with he sample text
> shown in support.sas.com/techsup/technote/ts140.pdf but I don't know
> exactly how much concordance is expected.  The time stamp in the file is
> today so I assume that the file was created today.
> 
> You asked "why [I] think this is a file that follows the format" -- I did
> not make that assumption; I merely attempted to read an XPT file with
> read.xport and it failed.
> 
> Could there be an issue with the version of SAS (which appears to be 6.06)
> -- they are now up to version 9 (for Windows - I don't know the version #
> for UNIX).
> 
> Dennis
> 
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
> 
> 
> 
> On Oct 4, 2013, at 4:47 PM, Duncan Murdoch <murdoch.duncan at gmail.com>
> wrote:
> 
> > On 13-10-04 6:50 PM, Dennis Fisher wrote:
> >> OS X 10.8
> >> R 3.0.1
> >> foreign 0.8-55 (2013-09-02)
> >>
> >> Colleagues,
> >>
> >> I received a SAS XPT file that I cannot read using the foreign package.
> >> The command:
> >> 	read.xport(FILENAME)
> >> results in the following message:
> >> 	Error in lookup.xport(file) : file not in SAS transfer format
> >> I am able to read the file successfully using StatTransport so it
> appears that the file is OK.
> >>
> >> When I examine the file using "more", the first few lines look like
> this:
> >> !04Oct13:11:15:5904Oct13:11:15:59
> 
> >> HEADER RECORD*******MEMBER  HEADER
> RECORD!!!!!!!000000000000000001600000000140
> 
> >> HEADER RECORD*******DSCRPTR HEADER
> RECORD!!!!!!!000000000000000000000000000000
> 
> >> SAS     SAS     SASDATA 6.06    bsd4.2
> !04Oct13:11:15:5904Oct13:11:15:59
> 
> >> HEADER RECORD*******NAMESTR HEADER
> RECORD!!!!!!!000000000500000000000000000000
> 
> >> !^A!^H!^ASubject Subject                                 BEST    !^L!
> !
> >> !^A!^H!^BPeriod  Period                                  BEST    !^L!
> !^H!
> >>
> >> Of course, I can use StatTransport to write the file to another format.
> However, I would like to understand why the foreign package is unable to
> process the file.
> >
> > That file doesn't follow the documented format linked to from
> ?read.xport.  You'll have to ask SAS why their documentation is incorrect,
> or ask yourself why you think this file is a file that follows that format
> when it doesn't.
> >
> > Duncan Murdoch
> >
> >
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list