CALL EXPORTMATRIXTOR (IMLMatrix, RMatrix);
You can use the EXPORTMATRIXTOR 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: ExportMatrixToR.
The arguments to the subroutine are as follows:
is a SAS/IML matrix that contains the data you want to transfer.
is a literal string or a character matrix that specifies the name of an R matrix to contain a copy of the data.
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 define a SAS/IML matrix and copy the data from the matrix to an R matrix called m
:
proc iml; a = {1 2 3, 4 . 6}; call ExportMatrixToR(a, "m"); submit / R; print(m) endsubmit;
To demonstrate that the data were successfully transferred, the print
function in the R language is used to print the values of the m
matrix. The output is shown in FigureĀ 25.129. Note that the SAS missing value in the SAS/IML matrix was automatically converted to the R missing value (NA
).
You can transfer data from an R matrix frame into a SAS/IML matrix by using the IMPORTMATRIXFROMR call . See ChapterĀ 12: Calling Functions in the R Language, for details about transferring data between R and SAS software.
The names of the variables in the R data frame are the same as in the SAS data set.