0

I am trying to import an xpt file into R using read.xport from both SASxport and foreign package but somehow I keep getting below error message:

Error in lookup.xport.inner(file) : 
  SAS transfer file has incorrect library header

The same error would also appear using sasxport.get() from Hmisc package. However, the file itself looks fine under SAS viewer on my PC. Has anyone encountered this problem before, or can you suggest of a solution? Thank you.

When openning the file using a text editor the header looks like this:

HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!000000000000000000000000000000  SAS     SAS     SASLIB  6.06    bsd4.2  
Joe
  • 62,789
  • 6
  • 49
  • 67
Xinting WANG
  • 1,905
  • 2
  • 15
  • 20
  • this might be an appropriate case to provide the actual file as a link so we can test in our own environment. also try ``sas7bdat`` – Cyrus Mohammadian Sep 14 '16 at 07:34
  • @CyrusMohammadian I understand that would be much easier.However, the file is a company propriety and I am not at a liberty to disclose it. Sorry. – Xinting WANG Sep 14 '16 at 07:37
  • http://grokbase.com/p/r/r-help/0161ma56c2/r-r-and-sas – Cyrus Mohammadian Sep 14 '16 at 07:41
  • Xport files are BINARY. If you move them from system to system make sure to move them as binary files and not ASCII files. If you insert or remove '0D'x characters then you will corrupt the file. – Tom Sep 14 '16 at 11:41
  • XPT files are not binary. See this from SAS technotes: "All transport data set records are 80 bytes in length. If there is not sufficient data to reach 80 bytes, then a record is padded with ASCII blanks to 80 bytes. All character data are stored in ASCII, regardless of the operating system." – IRTFM Jan 06 '18 at 17:08

1 Answers1

2

Two years after I posted this question I recently found that there is a function read_xpt() in package haven that works like a miracle.

I guess the frame work of this package is totally different from previous packages.

Xinting WANG
  • 1,905
  • 2
  • 15
  • 20