Skip to content
Prev 385412 / 398506 Next

Export R outputs to SAS dataset

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: