[R] importing sas datasets

John Kane jrkrideau at yahoo.ca
Sat Apr 21 02:11:21 CEST 2007


Hi Anna, 

I'm the sas.get problem man.

I still have not gotten it to work but I think that is
because I have some slightly dodgy SAS files. 
Assuming that the sas.get problem is what was
described in the earlier thread it appears to have
been fixed.  You might want to do an update to R to
get the most recent Hmisc. 

An alternative in Hmisc that Frank Harrell pointed out
is to do a SAS export file and a special version of
the format file.  

It is described in the Hmisc reference manual See
sasxport.get . It worked just fine for me on a couple
of test files. I don't remember but I think you're
stuck with the 8 character variable names though.


--- Daniel Nordlund <res90sx5 at verizon.net> wrote:

> > -----Original Message-----
> > From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]
> > On Behalf Of a.martino at crismaitalia.it
> > Sent: Friday, April 20, 2007 6:36 AM
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] importing sas datasets
> > 
> > Hello,
> > 
> > I wanted to ask help about importing sas datasets.
> > 
> > 1)I tried with some functions as read.ssd (foreign
> package),
> > but it doesn't import the file if the length of
> the
> > variables' names are longer than 8 bite (it has to
> conform
> > to the 6 version).
> > 
> > 2)I then tried with the sas.get function (Hmisc
> package) but
> > with the command:
> > 
> >  c<- sas.get(lib="c:\\ghan", mem="mkds0001",
> var=("   "),
> > format.library="d:\\R\\R-2.4.1",
> > sasprog="C:\\Programmi\\SAS\\SAS 9.1\\sas.exe")
> > 
> > R can't launch the sas.exe because there is a
> space in the
> > directory SAS 9.1.
> > 
> <<<snip>>>
> 
> Anna,
> 
> There has been a thread on this problem recently. 
> You could check the archives for posts with the
> subject "sas.get problem".  I can't comment about
> point 1, but the problem in point 2 has nothing to
> do with the space in the name.  (Well, it kind of
> does because it has to do with trying to get around
> the problem of spaces in path names).  
> 
> The problem you are having with sas.get is that the
> function is broken in the Windows version of Hmisc. 
> There is a fix which you can apply, and when that is
> done sas.get is a very nice function (I have heard
> that the problem will be fixed in an upcoming
> version of Hmisc).  Here is a solution that works
> for me and others.
> 1.  start up R interactively
> 2.  I will assume you have appropriately installed
> the Hmisc package
> 3.  load Hmisc by typing library(Hmisc) at the R
> prompt.
> 4.  type 'sas.get' (without the quotes) at the R
> prompt.  This will print the source code for the
> sas.get function definition.
> 5.  cut and paste the source code into the text
> editor of your choice and correct line 127 (change
> 'sys' to 'system'), i.e.  change line 127 from
> 
>     status <- sys(paste(shQuote(sasprog),
> shQuote(sasin), "-log", 
> 
> to
> 
>     status <- system(paste(shQuote(sasprog),
> shQuote(sasin), "-log",
> 
> 7.  next, sas.get needs to be redefined with the
> corrected code.  In your text editor, add 
> 
>      sas.get <- 
> 
> to the first line so that it reads
> 
>      sas.get <- function (library, member, variables
> = character(0), ifs = character(0),
> 
> 8.  save this corrected function definition as a
> text file (I chose Hmisc_sas_get_correction.R as the
> file name).
> 
> Now, any time you want to use sas.get from Hmisc you
> can take the following steps
> 1. start R
> 2. load Hmisc using 
> 
> library(Hmisc)
> 
> 3. source the corrected sas.get definition
> 
>    source("your_path/Hmisc_sas_get_correction.R")
> 
> Now you are set to go.  Let us know if this works
> for you.
> 
> Hope this is helpful,
> 
> Dan
> 
> Daniel Nordlund
> Bothell, WA
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> 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.
>



More information about the R-help mailing list