You can use the EXPORTDATASETTOR subroutine to transfer data from a SAS data set to an R data frame. It is easier to read the subroutine name when it is written in mixed case: ExportDataSetToR.
The arguments to the subroutine are as follows:
is a literal string or a character matrix that specifies the two-level name of a SAS data set (for example, Sashelp.Class
).
is a literal string or a character matrix that specifies the name of an R data frame.
You can call the subroutine provided that the following statements are true:
The R statistical software is installed on the SAS workspace server.
The SAS system administrator at your site has enabled the RLANG SAS system option. (See the section The RLANG System Option.)
The following statements copy data from the Sashelp.Class
data set into an R data frame called class
:
proc iml; call ExportDataSetToR("Sashelp.Class", "class"); submit / R; names( class ) endsubmit;
To demonstrate that the data were successfully transferred, the names
function in the R language is used to print the names of the variables in the R data frame. The output is shown in Figure 23.111.
You can transfer data from an R data frame into a SAS data set by using the IMPORTDATASETFROMR call. See Chapter 11: Calling Functions in the R Language, for details about transferring data between R and SAS software.