From p.dalgaard@biostat.ku.dk  Sun Dec 22 01:09:02 2002
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: Sun Dec 22 01:09:02 2002
Subject: [Rd] read.xport and lookup.xport in foreign (PR#2385)
In-Reply-To: <200212201748.SAA06803@pubhealth.ku.dk>
References: <200212201748.SAA06803@pubhealth.ku.dk>
Message-ID: <x2isxmc3tf.fsf@biostat.ku.dk>

fharrell@virginia.edu writes:

[How to create an xpt file that R cannot read...]
> Also I would greatly benefit from having lookup.xport return all of
> the SAS variable attributes, especially variable label and format
> name. I could then write a little function for the community that
> makes read.xport as comprehensive as read.spss in terms of creating
> factor variables and variable labels, if the user exports the PROC
> CONTENTS CNTLOUT= dataset.

If anyone is interested in trying to figure this stuff out, it would
be most welcome (information on the file format can be obtained via
the link http://www.wotsit.org/download.asp?f=sas). To save you the
trouble, here's the inverse of Frank's code, i.e., how to read the
stuff back into SAS:

libname x SASV5XPT "test.xpt";
libname y SASV5XPT "test2.xpt";
proc format cntlin=y.format;
proc contents data=x.test;
proc contents data=y.test;
proc contents data=y.format;
proc print data=x.test;
proc print data=y.test;
proc print data=y.format;

Notice in particular that nothing works without the proc format line,
SAS can't read test.xpt without somehow being told what the RACE
format is. One possibly relevant oddity is that SAS seems to claim
that RACE has length 4, not 3, in the contents listing.

(Of course, if you haven't already realized: Once we know how to
extract SAS format names and interpret user-supplied formats, people
are going to want us to be able to interpret standard formats like
DATETIME. as well....)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907



[Rd] read.xport and lookup.xport in foreign (PR#2385)
Peter Dalgaard BSA