Hi, I need to call an R program from Sas. I have tried using the following code in Sas using the x command but it just calls up dos and says 'D:\Program' is not recognized as an internal or external command, operable program or batch file. ] SAS CODE: options xwait xsync; %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable Disease Analaysis\R graphics; options xwait xsync; x '"D:\Program Files\R\R-2.9.2\bin\Rgui.exe" --no-save --quiet <""&rsource.\Rtest.R""> ""&rsource.\Rtest.log""'; What I need it to do is call R, run an R program and then go back to running sas. Any ideas on how to do that? Thanks! Sarah -- --- Sarah Jilani (317) 979 2830 [[alternative HTML version deleted]]
Sarah, This is a SAS question, not R. However, it seems clear that it has something to do with the fact that there are spaces in the command that you're sending to Windows. Maybe try calling with the 'short directory name' notation, I forget what that's called in Windows. Or else follow-up on a SAS list? Sarah Jilani wrote:> Hi, > > I need to call an R program from Sas. I have tried using the following code > in Sas using the x command but it just calls up dos and says > 'D:\Program' is not recognized as an internal or external command, operable > program or batch file. > ] > SAS CODE: > > options xwait xsync; > > %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable > Disease Analaysis\R graphics; > > options xwait xsync; > > x '"D:\Program Files\R\R-2.9.2\bin\Rgui.exe" --no-save --quiet > <""&rsource.\Rtest.R""> ""&rsource.\Rtest.log""'; > > What I need it to do is call R, run an R program and then go back to running > sas. Any ideas on how to do that? > > Thanks! > > Sarah >
On Sep 15, 2010, at 1:44 PM, Sarah Jilani wrote:> Hi, > > I need to call an R program from Sas. I have tried using the > following code > in Sas using the x command but it just calls up dos and saysI went searching for a worked example and found this: http://www.nesug.org/proceedings/nesug08/sa/sa07.pdf Those of us with a preference for R are likely to be either amused (or mildly offended) by statements like ..."Data manipulation is much easier in SAS..." but at least the author recognizes the superiority of graphics and time series analysis features.> 'D:\Program' is not recognized as an internal or external command, > operable > program or batch file. > ] > SAS CODE: > > options xwait xsync; > > %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic > Communicable > Disease Analaysis\R graphics; > > options xwait xsync; > > x '"D:\Program Files\R\R-2.9.2\bin\Rgui.exe" --no-save --quietAs I suspected the program example did not call Rgui.exe, but rather R.exe -- David.> <""&rsource.\Rtest.R""> ""&rsource.\Rtest.log""'; > > What I need it to do is call R, run an R program and then go back to > running > sas. Any ideas on how to do that? > > Thanks! > > Sarah > > -- > --- > Sarah Jilani > (317) 979 2830 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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.David Winsemius, MD West Hartford, CT
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Sarah Jilani > Sent: Wednesday, September 15, 2010 10:44 AM > To: r-help at r-project.org > Subject: [R] Sas to R > > Hi, > > I need to call an R program from Sas. I have tried using the following > code > in Sas using the x command but it just calls up dos and says > 'D:\Program' is not recognized as an internal or external command, > operable > program or batch file. > ] > SAS CODE: > > options xwait xsync; > > %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic > Communicable > Disease Analaysis\R graphics; > > options xwait xsync; > > x '"D:\Program Files\R\R-2.9.2\bin\Rgui.exe" --no-save --quiet > <""&rsource.\Rtest.R""> ""&rsource.\Rtest.log""'; > > What I need it to do is call R, run an R program and then go back to > running > sas. Any ideas on how to do that? > > Thanks! > > Sarah >Sarah, I have found that making sure the command you wish to run will actually run at the command line is a big help. I suspect that the command, as you have specified it, will not run at the command line. Try copying everything inside the single quotes, open a command prompt, then paste the command and run it. I don't think it will do what you expect or want. That being said, try something like x '"D:\Program Files\R\R-2.9.2\bin\R.exe" --no-save --quiet < "&rsource.\Rtest.R" > "&rsource.\Rtest.log"'; You don't want to run Rgui.exe, use R.exe. In addition, you don't want to double your double-quotes, because they are inside single-quotes. Doubling them will cause problems. If this doesn't work, then the R-help related issue is figuring out how to run R from the command line with input and output redirection. The syntax I provide above should run just fine in Windows XP/Vista/7. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
Hi Sarah, Just a couple additional notes to what's been said: 1) It seems like R CMD BATCH might be easier 2) If the space in Program Files is causing issues, you can use the Windows environment variable %PROGRAMFILES% (which also means you do not need the drive letter. 3) I find it handy to define a new Windows environment variable with the path to R, then I can just reference that rather than the entire path (a google search will show you lots of ways to do this via the GUI and the command prompt). For instance: "%R%/Rterm.exe" starts R in the command prompt for me. Here is an example run from the Windows command prompt: "%PROGRAMFILES%/R/R-2.11.1/bin/R.exe" CMD BATCH "C:/myscript.R" "C:/results.txt" Cheers, Josh On Wed, Sep 15, 2010 at 10:44 AM, Sarah Jilani <sarahjilani at gmail.com> wrote:> Hi, > > I need to call an R program from Sas. I have tried using the following code > in Sas using the x command but it just calls up dos and says > 'D:\Program' is not recognized as an internal or external command, operable > program or batch file. > ] > SAS CODE: > > options xwait xsync; > > %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable > Disease Analaysis\R graphics; > > options xwait xsync; > > x '"D:\Program Files\R\R-2.9.2\bin\Rgui.exe" --no-save --quiet > <""&rsource.\Rtest.R""> ""&rsource.\Rtest.log""'; > > What I need it to do is call R, run an R program and then go back to running > sas. Any ideas on how to do that? > > Thanks! > > Sarah > > -- > --- > Sarah Jilani > (317) 979 2830 > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/