Re: [R] Reading xpt files into R

2018-04-14 Thread peter dalgaard
That's what he tried, but the bottom line is that just because something is 
called foo.xpt there is no guarantee that it actually is a SAS XPORT file. 
Firefox plugins use the same extension but it could really be anything - naming 
conventions are just that: conventions.

So dig deeper and find out what the file really is (or was supposed to be). 

-pd

> On 14 Apr 2018, at 00:18 , David Winsemius  wrote:
> 
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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.


Re: [R] Reading xpt files into R

2018-04-13 Thread David Winsemius

> On Apr 13, 2018, at 10:01 AM, WRAY NICHOLAS via R-help  
> 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!!!00  
SAS SAS SASLIB  9.2 XP_PRO
16SEP09:09:39:2516SEP09:09:39:25
HEADER RECORD***MEMBER  HEADER 
RECORD!!!016140  HEADER RECORD***DSCRPTR HEADER 
RECORD!!!00  SAS DEMOSASDATA 9.2 
XP_PRO16SEP09:09:39:2516SEP09:09:39:25
HEADER RECORD***NAMESTR 
HEADER RECORD!!!000144  SEQNRespondent 
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.


[R] Reading xpt files into R

2018-04-13 Thread WRAY NICHOLAS via R-help
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...
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.