[R] Export R outputs to SAS dataset
Daniel Nordlund
djnord|und @end|ng |rom gm@||@com
Tue Aug 25 00:56:47 CEST 2020
It is still not clear to me (1) if you just want the printed output in
your SAS list file, or (2) if you want the actual numerical results
returned to SAS so that you can do more manipulation with the numbers.
If (1) you can precede your R code with sink() to output to your SAS
list file
#--------R libraries---------
sink('path/to/your/listfile.lst', append=TRUE)
library(tidyverse)
library(MF)
MFSubj(lesion ~ group, calflung)
HLBoot(lesion ~ group, calflung, compare = c("con", "vac"), b = 100,
B = 100, alpha = 0.05, hpd = TRUE, bca = FALSE,
return.boot = FALSE, trace.it <http://trace.it> = FALSE, seed
= NULL)
You will probably need to redirect your SAS list file to the same location
PROC PRINTTO file='path/to/your/listfile.lst' new;
If (2), then you need to store the output from you function into
variables that you can examine to see what you may want to import into
SAS. So, something like this in R
mfsubj <- MFSubj(lesion ~ group, calflung)
hlboot <- HLBoot(lesion ~ group, calflung, compare = c("con", "vac"), b
= 100,
B = 100, alpha = 0.05, hpd = TRUE, bca = FALSE,
return.boot = FALSE, trace.it = FALSE, seed = NULL)
str(mfsubj)
str(hlboot)
After examining the output, you will know what variables/dataframes you
want to import and you can use the functions provided by PROC IML for
that purpose. You will need to read the SAS documentation to understand
how to do that.
This is becoming off topic for R-Help, so let me end with suggesting you
pursue this question either on SAScommunity or the SAS-L listserve. You
might also want to look into SAS Viya for running your R code. If you
want to continue this off-list, I can try to help you more, but I will
need to better understand what it is that you want to get back into SAS.
Dan
On 8/23/2020 6:46 AM, Jomy Jose wrote:
> Hi Daniel
>
> Thanks,please find the code and output
>
> #--------R libraries---------
> library(tidyverse)
> library(MF)
>
>
> MFSubj(lesion ~ group, calflung)
> HLBoot(lesion ~ group, calflung, compare = c("con", "vac"), b = 100,
> B = 100, alpha = 0.05, hpd = TRUE, bca = FALSE,
> return.boot = FALSE, trace.it <http://trace.it> = FALSE,
> seed = NULL)
>
>
> 10000 bootstrap samples
> 95% confidence intervals
> Comparing vac to con
>
>
> Mitigated Fraction
>
> observed median lower upper
> Equal Tailed 0.44 0.4464 0.1360 0.7024
> Highest Density 0.44 0.4464 0.1456 0.7088
>
>
> Hodges-Lehmann
>
> observed median lower upper
> Equal Tailed -0.07335 -0.07125 -0.170425 -0.01480
> Highest Density -0.07335 -0.07125 -0.156350 -0.00975
>
>
> Quartile Differences (quartiles of vac - quartiles of con)
>
> observed median lower upper
> Q25 -0.041500 -0.041300 -0.10340 -0.000905
> Q50 -0.112525 -0.111175 -0.28115 0.019350
> Q75 -0.168000 -0.170425 -0.38650 0.030000
>
>
> Quartiles of con
> observed median lower upper
> Q25 0.054000 0.054000 0.01525 0.11275
> Q50 0.139275 0.139275 0.06140 0.31000
> Q75 0.315000 0.315000 0.17300 0.45250
>
>
> Quartiles of vac
> observed median lower upper
> Q25 0.01250 0.01250 0.00125 0.026000
> Q50 0.02675 0.02675 0.01665 0.144575
> Q75 0.14700 0.14700 0.02810 0.292000
>
>
> Best
> Jose
>
> On Sun, Aug 23, 2020 at 2:44 AM Daniel Nordlund <djnordlund using gmail.com
> <mailto:djnordlund using gmail.com>> wrote:
>
> On 8/22/2020 9:05 AM, Rasmus Liland wrote:
> > On 2020-08-22 08:17 +0530, Jomy Jose wrote:
> > | Hi
> > | I was able to run R code via PROC IML
> > | in SAS,so is there any way to export
> > | the generated outputs to SAS datasets
> > | since the R outputs don't follow data
> > | frame structure.
> >
> > Dear Jomy,
> >
> > But perhaps you can take the outputs in
> > SAS and work on them inside from there?
> >
> > To export a data frame from R to SAS via
> > a file[1], you can use
> >
> > foreign::write.foreign(..., package="SAS")
> >
> > But I have not tried it.
> >
> > I have used foreign::read.spss before,
> > hehe :-)
> >
> > I know R is also possible to call from
> > Julia, and the df appearing in Julia,
> > this sounds like it should be possible
> > SAS too[2], yes?
> >
> > Best,
> > Rasmus
> >
> > [1] https://www.statmethods.net/input/exportingdata.html
> <https://www.statmethods.net/input/exportingdata.html>
> > [2]
> https://documentation.sas.com/?docsetId=imlug&docsetTarget=imlug_r_sect012.htm&docsetVersion=15.1&locale=en
> <https://documentation.sas.com/?docsetId=imlug&docsetTarget=imlug_r_sect012.htm&docsetVersion=15.1&locale=en>
> >
> > ______________________________________________
> > R-help using r-project.org <mailto:R-help using r-project.org> mailing list
> -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> <http://www.R-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
>
> Can you give a reproducible example of the R-code you are running and
> the R "output" you want to get back in SAS? It is difficult from way
> over here to know if you are wanting numerical results like means or
> regression coefficients ... or if you just want printed output in
> your
> SAS log or listing.
>
> Dan
>
> --
> Daniel Nordlund
> Port Townsend, WA USA
>
--
Daniel Nordlund
Port Townsend, WA USA
More information about the R-help
mailing list