CALL IMPORTMATRIXFROMR (IMLMatrix, RExpr);
You can use the IMPORTMATRIXFROMR subroutine to transfer data from an R data frame to a SAS data set. It is easier to read the subroutine name when it is written in mixed case: ImportMatrixFromR.
The arguments to the subroutine are as follows:
is a SAS/IML matrix to contain the data you want to transfer.
is a literal string or a character matrix that specifies the name of an R matrix, data frame, or an R expression that can be coerced to an R data frame.
If the RExpr argument is a data frame, then the resulting SAS/IML matrix has columns that correspond to variables from the data frame. If the first variable in the data frame is a numeric variable, a numeric matrix is created from all numeric variables in the data frame. If the first variable in the data frame is a character variable, a character matrix is created from all character variables in the 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 define an R matrix and copy the data from the matrix to a SAS/IML matrix:
proc iml; submit / R; m <- matrix( c(1,2,3,4,NA,6), nrow=2, byrow=TRUE) endsubmit; call ImportMatrixFromR(a, "m"); print a;
To demonstrate that the data were successfully transferred, the PRINT statement is used to print the values of the a
matrix. The output is shown in FigureĀ 25.166. Note that the R missing value (NA
) in the R matrix m
was automatically converted to the SAS missing value in the SAS/IML matrix, a
.
You can transfer data from a SAS/IML matrix into an R matrix frame by using the EXPORTMATRIXTOR call . See ChapterĀ 12: Calling Functions in the R Language, for details about transferring data between R and SAS software.