<- "proc freq data=work.in_df; tables cyl / out=work.out_df; run;"
SAS_code manipulate_df_in_SAS(in_df = mtcars,
SAS_location = "C:/Program Files/SASHome/SASFoundation/9.4",
SAS_code = SAS_code)
Creating your own custom solution
If the other solutions in this guide don’t meet your needs, you can create your own custom solution by making use of proc iml
, the ImportDataSetFromR
and ExportDataSetToR
subroutines, and the RLANG
option that were described in the RLANG
section of this guide.
For example, you can create a function that looks something like this:
In the above example, the manipulate_df_in_SAS
function takes three arguments. The first is in_df
, which is an R data frame that you would like to manipulate in SAS. The second argument, SAS_location
, is used to specify the folder path to your SAS installation on your machine. The third argument is SAS_code
, where the SAS code to apply to in_df
is specified.
This function assumes that, in SAS, you have access to a SAS dataset named in_df
. The out_df
SAS dataset will eventually be passed back to the user in R as an R data frame.
In terms of the actual implementation, this function works by first creating a temporary file folder. The user-inputted R data frame is then saved in the temporary file folder as a .RDS
file. From here, a temporary SAS program is created. The user-inputted SAS code is then inserted into the temporary SAS program, making use of proc iml
and the ImportDataSetFromR
and the ExportDataSetToR
subroutines. The temporary SAS program is then executed by sending a command to the command prompt, enabling the RLANG
option at execution time. Finally, the results are brought back into R, the temporary files are deleted, and the resulting R data frame is returned to the user.