Re: [R] Fwd: Re: Reading xpt files into R

2018-04-14 Thread William Dunlap via R-help
 > When I look at the SASxport::read.xport function code, it is in fact,
_not_ the
> same function. But it does have the R statement about what it thinks
> qualifies as a SAS xprot file:
>
> xport.file.header <- "HEADER RECORD***LIBRARY HEADER 
> RECORD!!!00
"
>
> It checks to see whether the file starts with that string.

Version 8 SAS xport files have the header
  HEADER RECORD***LIBV8 HEADER RECORD!!!0
0
It is easy to check for that in your text editor or in R.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Apr 14, 2018 at 1:30 PM, David Winsemius 
wrote:

>
> > On Apr 14, 2018, at 12:18 PM, WRAY NICHOLAS via R-help <
> r-help@r-project.org> wrote:
> >
> >
> >  Original Message --
> > From: WRAY NICHOLAS 
> > To: peter dalgaard 
> > Date: 14 April 2018 at 20:18
> > Subject: Re: [R] Reading xpt files into R
> >
> >
> > Well yesterday I'd downloaded the "foreign" package and tried to open
> the xpt file using that:
> >
> > library(foreign)
> > read.xport("test.xpt")
> >
> > I got the following error and warning messages:
> >
> >> read.xport("test.xpt")
> > Error in read.xport("test.xpt") :
> > The specified file does not start with a SAS xport file header!
> > In addition: Warning message:
> > In readBin(file, what = character(0), n = 1, size =
> nchar(xport.file.header,  :
> > null terminator not found: breaking string at 1 bytes
> >
> > I can open the xpt using wordpad and there is a header but it seems to
> be just text.  I really don't know what constitutes an "
> > SAS xport file header"
>
> I'm not sure why Peter deleted my copy of a sample of a SAS xport header
> that I took from an NHANES data distribution. He seemed to think I was
> confused about the function you had been using. The reason I mentioned that
> `read.xport` was from the 'foreign' package is that one generally loads
> that package to make the function available, while it appears you were
> using a different package, SASxport, and I didn't know whether that package
> had a function which had the same name as the one from pkg-foreign, and if
> it did whether it might depend on the read.xport function in foreign. You
> should not need to download the 'foreign' package, since it ships with
> every distribution of R. These are the arguments accepted by that function:
>
> SASxport::read.xport
> function (file, force.integer = TRUE, formats = NULL, name.chars = NULL,
> names.tolower = FALSE, keep = NULL, drop = NULL, as.is = 0.95,
> verbose = FALSE, as.list = FALSE, include.formats = FALSE)
>
>
>  When I look at the SASxport::read.xport function code, it is in fact,
> _not_ the same function. But it does have the R statement about what it
> thinks qualifies as a SAS xprot file:
>
> xport.file.header <- "HEADER RECORD***LIBRARY HEADER 
> RECORD!!!00
> "
>
> It checks to see whether the file starts with that string.
>
> This is what appeared in my first message:
>
> >
> > 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_PRO
> 16SEP09:09:39:2516SEP09:09:39:25
>   HEADER RECORD***NAMESTR HEADER 
> RECORD!!!000144
>SEQNRespondent sequence number
>
> So the header is text, but it is text with a particular structure. If your
> file doesn't have that structure, then it's not a SAS xport file. The .xpt
> extension is also used for Mozilla Firefox plugins.
>
>
> >
> > Nick
> >
> >
> >
> > On 14 April 2018 at 10:32 peter dalgaard  wrote:
> >
> > That's what he tried,
>
> Actually not, Peter. Wray was using a function of the same name, but not
> from pkg-foreign. Perhaps he was following the tutorial at:
>
> http://www.phusewiki.org/wiki/index.php?title=Open_XPT_File_with_R
>
>
> > 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).
>
> Peter and I agree agree on that advice.
>
> >
> > -pd
> >
> >>
> >>On 14 Apr 2018, at 00:18 , David Winsemius <
> dwinsem...@comcast.net> wrote:
> >>
> >>There is a read.xport function in 

Re: [R] Fwd: Re: Reading xpt files into R

2018-04-14 Thread David Winsemius

> On Apr 14, 2018, at 12:18 PM, WRAY NICHOLAS via R-help  
> wrote:
> 
> 
>  Original Message --
> From: WRAY NICHOLAS 
> To: peter dalgaard 
> Date: 14 April 2018 at 20:18
> Subject: Re: [R] Reading xpt files into R
> 
> 
> Well yesterday I'd downloaded the "foreign" package and tried to open the xpt 
> file using that:
> 
> library(foreign)
> read.xport("test.xpt")
> 
> I got the following error and warning messages:
> 
>> read.xport("test.xpt")
> Error in read.xport("test.xpt") : 
> The specified file does not start with a SAS xport file header!
> In addition: Warning message:
> In readBin(file, what = character(0), n = 1, size = nchar(xport.file.header,  
> :
> null terminator not found: breaking string at 1 bytes
> 
> I can open the xpt using wordpad and there is a header but it seems to be 
> just text.  I really don't know what constitutes an "
> SAS xport file header"

I'm not sure why Peter deleted my copy of a sample of a SAS xport header that I 
took from an NHANES data distribution. He seemed to think I was confused about 
the function you had been using. The reason I mentioned that `read.xport` was 
from the 'foreign' package is that one generally loads that package to make the 
function available, while it appears you were using a different package, 
SASxport, and I didn't know whether that package had a function which had the 
same name as the one from pkg-foreign, and if it did whether it might depend on 
the read.xport function in foreign. You should not need to download the 
'foreign' package, since it ships with every distribution of R. These are the 
arguments accepted by that function:

SASxport::read.xport
function (file, force.integer = TRUE, formats = NULL, name.chars = NULL, 
names.tolower = FALSE, keep = NULL, drop = NULL, as.is = 0.95, 
verbose = FALSE, as.list = FALSE, include.formats = FALSE) 


 When I look at the SASxport::read.xport function code, it is in fact, _not_ 
the same function. But it does have the R statement about what it thinks 
qualifies as a SAS xprot file:

xport.file.header <- "HEADER RECORD***LIBRARY HEADER 
RECORD!!!00  "

It checks to see whether the file starts with that string.

This is what appeared in my first message:

> 
> 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_PRO16SEP09:09:39:2516SEP09:09:39:25
> HEADER RECORD***MEMBER  
> HEADER RECORD!!!016140  HEADER 
> RECORD***DSCRPTR HEADER RECORD!!!00  SAS  
>DEMOSASDATA 9.2 XP_PRO
> 16SEP09:09:39:2516SEP09:09:39:25  
>   HEADER RECORD***NAMESTR HEADER 
> RECORD!!!000144  SEQNRespondent sequence 
> number 

So the header is text, but it is text with a particular structure. If your file 
doesn't have that structure, then it's not a SAS xport file. The .xpt extension 
is also used for Mozilla Firefox plugins.


> 
> Nick
> 
> 
> 
> On 14 April 2018 at 10:32 peter dalgaard  wrote:
> 
> That's what he tried,

Actually not, Peter. Wray was using a function of the same name, but not from 
pkg-foreign. Perhaps he was following the tutorial at:

http://www.phusewiki.org/wiki/index.php?title=Open_XPT_File_with_R


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

Peter and I agree agree on that advice.

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

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, 

Re: [R] Fwd: Re: Reading xpt files into R

2018-04-14 Thread William Dunlap via R-help
Does read.xport read both version 5 and version 8 xpt files?  This link to
the Library of Congress can get you started on how to interpret the
header.  (It states that Version 8 was introduced in 2012 but was not in
wide use as of early 2017.)

https://www.loc.gov/preservation/digital/formats/fdd/fdd000464.shtml

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Apr 14, 2018 at 12:18 PM, WRAY NICHOLAS via R-help <
r-help@r-project.org> wrote:

>
>  Original Message --
> From: WRAY NICHOLAS 
> To: peter dalgaard 
> Date: 14 April 2018 at 20:18
> Subject: Re: [R] Reading xpt files into R
>
>
> Well yesterday I'd downloaded the "foreign" package and tried to open the
> xpt file using that:
>
> library(foreign)
> read.xport("test.xpt")
>
> I got the following error and warning messages:
>
> > read.xport("test.xpt")
> Error in read.xport("test.xpt") :
> The specified file does not start with a SAS xport file header!
> In addition: Warning message:
> In readBin(file, what = character(0), n = 1, size =
> nchar(xport.file.header,  :
> null terminator not found: breaking string at 1 bytes
>
> I can open the xpt using wordpad and there is a header but it seems to be
> just text.  I really don't know what constitutes an "
> SAS xport file header"
>
> Nick
>
>
>
> On 14 April 2018 at 10:32 peter dalgaard  wrote:
>
> 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 <
> dwinsem...@comcast.net> 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
>
>
>
>
>
>
> [[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.
>

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