[R] importing sas datasets

Daniel Nordlund res90sx5 at verizon.net
Fri Apr 20 19:18:57 CEST 2007


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



More information about the R-help mailing list