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. Is it possible that R can't import sas datasets with variables' names' length longer than 8 bites? Could you help in any of the two cases? thank you Anna Emilia Martino
> -----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
Hi John and Daniel, Thanks for your suggestions, I updated line 127 of the sas.get function but after submitting the following 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"') (also trying with sasprog="C:\\Programmi\\SAS\\SAS 9.1\\sas.exe") the log signaled the following error: Errore in system(paste(shQuote(sasprog), shQuote(sasin), "-log", shQuote(log.file)), : unused argument(s) (output = FALSE) which is about the modified 127 line. I've also tried with export files, with the sasxport.get function, it works out well, but only if the length of the variables' names' is maximum 8 bites. regards, Anna Emilia Martino ----- Original Message ----- Da : John Kane <jrkrideau at yahoo.ca> A : Daniel Nordlund <res90sx5 at verizon.net>, a.martino at crismaitalia.it, r-help at stat.math.ethz.ch Oggetto : Re: [R] importing sas datasets Data : Fri, 20 Apr 2007 20:11:21 -0400 (EDT)> 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. > > > > > > Make free worldwide PC-to-PC calls. Try the new > Yahoo! Canada Messenger with Voice at > http://ca.messenger.yahoo.com/
> -----Original Message----- > From: a.martino at crismaitalia.it [mailto:a.martino at crismaitalia.it] > Sent: Monday, April 23, 2007 8:45 AM > To: John Kane; Daniel Nordlund; r-help at stat.math.ethz.ch > Subject: Re: [R] importing sas datasets > > Hi John and Daniel, > > Thanks for your suggestions, I updated line 127 of the > sas.get function but after submitting the following > command: > > c<- sas.get(lib="c:\\ghan", mem="mkds0001", var=(" "),Why are you using parentheses in the line above for the var parameter? If you want all variables, just leave the var parameter out of the call (it defaults to all variables). But if you want to include it, the function call could be: 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") Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA
Hi Dan, thanks for the help, I'll try to resolve the sas.get problem in a second moment , actually I bypassed the problem creating a .csv file from my dataset and then using the read.csv function to import it into R. The only problem is that R imports only a 1000 observations, is that normal? Or did I have to specify an option? thanks and have a nice day Anna ----- Original Message ----- Da : "Daniel Nordlund" <res90sx5 at verizon.net> A : <a.martino at crismaitalia.it>, <r-help at stat.math.ethz.ch> Oggetto : RE: [R] importing sas datasets Data : Mon, 23 Apr 2007 13:09:47 -0700> Anna, > > My comment about var=(" ") being the problem is probably > wrong. Apparently R and the sas.get function can handle > that specification just fine (I have some learning to do > myself). I have a question about the error message below. > > > -----Original Message----- > > From: a.martino at crismaitalia.it > > [mailto:a.martino at crismaitalia.it] Sent: Monday, April > > 23, 2007 8:45 AM To: John Kane; Daniel Nordlund; > > r-help at stat.math.ethz.ch Subject: Re: [R] importing sas > > datasets > > Hi John and Daniel, > > > > Thanks for your suggestions, I updated line 127 of the > > sas.get function but after submitting the following > > 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"') (also > > trying with sasprog="C:\\Programmi\\SAS\\SAS > > 9.1\\sas.exe") > > the log signaled the following error: > > > > Errore in system(paste(shQuote(sasprog), shQuote(sasin), > > "-log", shQuote(log.file)), : > > unused argument(s) (output = FALSE) > > The error says there are unused arguments in the system > function call. So that's where I would focus to try to > solve this problem. However, I can't replicate the > problem on my Windows XP Pro system. So at this point I > can't be of much help. > > Sorry I can't be more helpful at this time, > > Dan > > Daniel Nordlund > Bothell, WA USA >