Interfacing with SAS

The interface between an IMLPlus program and the rest of SAS consists of two elements: the SAS class, and SAS data sets.

The SAS class provides methods that enable an IMLPlus program to submit SAS language statements to the SAS server on which the IMLPlus program is running. Unlike other IMLPlus classes such as ScatterPlot, the SAS class provides only static methods that implicitly reference the SAS server on which the IMLPlus program is running. For detailed information about the SAS class, please refer to the topic Class SAS.

The most frequently used method in the SAS class is SubmitStatements. This method passes a string containing one or more SAS language statements to the SAS server for processing. IMLPlus provides a very convenient shortcut for calling the method SubmitStatements: the SUBMIT statement. When IMLPlus encounters a SUBMIT statement, it passes the program source code between the SUBMIT statement and the following ENDSUBMIT statement to the method SAS.SubmitStatements. (Note that it is still necessary to call the method SAS.SubmitStatements directly in situations where the IMLPlus program builds SAS language statements dynamically.)

Data must be transferred between an IMLPlus program and other SAS components through SAS data sets. You cannot directly transfer an IML matrix to a DATA or PROC step. Because IMLPlus uses the same WORK library as DATA/PROC steps, the task of transferring data is quite easy.

Example

This example demonstrates calling PROC REG from an IMLPlus program. The program performs the following actions:

  1. Uses standard IML statements to create two IML matrices.
  2. Uses standard IML statements to store the matrices in a SAS data set.
  3. Uses the SUBMIT statement to call PROC REG to perform a linear fit of the data.
  4. Uses standard IML statements to read the output data set from PROC REG.
  5. Uses the DataObject and LinePlot classes to plot the original data and the linear fit.
x = t( do( 0, 6.28, .1 ) );
y = sin( x );

create imldata var{ x, y };
append;
close imldata;

submit;
proc reg data=imldata;
    model y=x;
    output out=regfit p=p;
    run;
endsubmit;

use regfit;
read all var {p} into p;
close regfit;

declare DataObject dobj;
dobj = DataObject.Create( "Example" );
dobj.AddVar( "X", x );
dobj.AddVar( "Y", y );
dobj.AddVar( "P", p );

declare LinePlot plot;
plot = LinePlot.Create( dobj, "X", {"Y" "P"}, false );
plot.ConnectPoints( "Y", false );
plot.ShowPoints( "P", false );
plot.ShowWindow();