> On Apr 13, 2018, at 10:01 AM, WRAY NICHOLAS via R-help <r-help@r-project.org> 
> wrote:
> 
> Hello R folk
> 
> I have an xpt file which I have been trying to open into R in R studio
> 
> On the net I found guidance which says that I need packages Hmisc and 
> SASxport which I have successfully loaded.
> 
> I had also found some code which says that this would allow me to read the 
> xpt file into R:
> 
> library(SASxport)
> data(Alfalfa)
> lookup.xport("test.xpt")
> Alfalfa<-read.xport("test.xpt")
> 
> I have set the directory correctly as far as I am aware, but when I tried to 
> run this code I got the following error messages:
> 
>> lookup.xport("test.xpt")
> Error in lookup.xport.inner(file) : file not in SAS transfer format
>> Alfalfa<-read.xport("test.xpt")
> Error in read.xport("test.xpt") : 
> The specified file does not start with a SAS xport file header!
> 
> I neither know what the file being not in SAS transfer format means, nor what 
> not starting with an SAS xport file header means either...

The "export" or "transfer format from SA is supposed to make reading data less 
difficult and standardized. This is what a header from the version used by the 
NHANES releases (that's all one line):

HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!000000000000000000000000000000  
SAS     SAS     SASLIB  9.2     XP_PRO                        
16SEP09:09:39:2516SEP09:09:39:25                                                
                HEADER RECORD*******MEMBER  HEADER 
RECORD!!!!!!!000000000000000001600000000140  HEADER RECORD*******DSCRPTR HEADER 
RECORD!!!!!!!000000000000000000000000000000  SAS     DEMO    SASDATA 9.2     
XP_PRO                        16SEP09:09:39:2516SEP09:09:39:25                
                                                HEADER RECORD*******NAMESTR 
HEADER RECORD!!!!!!!000000014400000000000000000000  SEQN    Respondent 
sequence number                              

You can look at the file with a text editor.

There is a read.xport function in the foreign package and I think most people 
would have chosen that one as a first attemp. It's part of the standard R 
distribution. It refers you to 
https://support.sas.com/techsup/technote/ts140.pdf for details on the format.

-- 
David.
> If anyone can explain how I can read this xpt file into R I'd be v grateful
> 
> Thanks Nick Wray
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to