EXPORTMATRIXTOR Call

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:

IMLMatrix

is a SAS/IML matrix that contains the data you want to transfer.

RMatrix

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:

  1. The R statistical software is installed on the SAS workspace server.

  2. 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 24.127. Note that the SAS missing value in the SAS/IML matrix was automatically converted to the R missing value (NA).

Figure 24.127: Output from R

     A1 A2 A3                                                                   
[1,]  1  2  3                                                                   
[2,]  4 NA  6                                                                   


You can transfer data from an R matrix frame into a SAS/IML matrix by using the IMPORTMATRIXFROMR call. See Chapter 11: 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.