Exchanging Data With Server-Side R

The mechanisms for exchanging data with server-side R are somewhat different from those used to exchange data with client-side R. To exchange data with server-side R, use only the following built-in IML subroutines:

ExportDataSetToR

ExportMatrixToR

ImportDataSetFromR

ImportMatrixFromR

These subroutines are documented in the SAS/IML User's Guide in the chapter Language Reference.

IMPORTANT: The built-in IML subroutines for exchanging data with server-side R have the same names and parameters as the IMLPlus modules for exchanging data with client-side R. Be sure to use the CALL statement to invoke the built-in IML subroutines and the RUN statement to invoke the IMLPlus modules.

If you make a mistake and accidentally use the RUN statement with one of the built-in subroutine names, IMLPlus will attempt to access the data using client-side R, if it is available. This will almost certainly result in an error message. Consider the following erroneous program:

submit / R server;
x <- 1
endsubmit;

run ImportMatrixFromR( x, "x" ); /* mistake: should use CALL statement */
print x;

When run, this program will experience an error because the RUN statement will invoke the IMLPlus module ImportMatrixFromR, which expects to retrieve a matrix from client-side R. However, the program assigned the matrix "x" using server-side R. Mistakes of this nature can also be made in the opposite manner:

submit / R;
x <- 1
endsubmit;

call ImportMatrixFromR( x, "x" ); /* mistake: should use RUN statement */
print x;

When run, this program will experience an error because the CALL statement will invoke the built-in IML subroutine ImportMatrixFromR, which expects to retrieve a matrix from server-side R. However, the program assigned the matrix "x" using client-side R.

The rule is:

Use the CALL statement when dealing with server-side R and use the RUN statement when dealing with client-side R.

With PROC IML, you can use either the CALL statement or the RUN statement to invoke the four R data exchange subroutines because there are no modules with corresponding names. PROC IML only supports interacting with server-side R.

To learn more about exchanging data with server-side R, please refer to the section Transferring Data between SAS and R Software in the chapter Calling Functions in the R Language in the SAS/IML User's Guide.