This section describes how to call a procedure from PROC IML.
Suppose you have data in a SAS/IML matrix that you want to analyze by using a statistical procedure. In general, you can use the following steps to analyze the data:
Of course, if the data are already in a SAS data set, you can skip the first step. Similarly, if you are solely interested in the printed output from a procedure, you can skip the third and fourth steps.
The following example calls the UNIVARIATE procedure in Base SAS software to compute a regression analysis. In order to tell the SAS/IML language interpreter that you want certain statements to be sent to the SAS System, you must enclose your SAS statements with SUBMIT and ENDSUBMIT statements. The ENDSUBMIT statement must appear on a line by itself.
The following statements create a SAS data set from data in a vector:
proc iml; q = {3.7, 7.1, 2, 4.2, 5.3, 6.4, 8, 5.7, 3.1, 6.1, 4.4, 5.4, 9.5, 11.2}; create MyData var {q}; append; close MyData;
The MyData
data set is used in the rest of this chapter.
You can call the UNIVARIATE procedure to analyze these data. The following statements use the ODS SELECT statement to limit the output from the UNIVARIATE procedure. The output is shown in Figure 10.1.
submit; ods select Moments; proc univariate data=MyData; var q; ods output Moments=Moments; run; endsubmit;
The previous statements also used the ODS OUTPUT statement to create a data set named Moments
that contains the statistics shown in Figure 10.1. In the data set, the first column of Figure 10.1 is contained in a variable named Label1
and the second column is contained in a variable named nValue1
. The following statements read those variables into SAS/IML vectors of the same names and print the values:
use Moments; read all var {"nValue1" "Label1"}; close Moments; labl = "Statistics for " + name(q); print nValue1[rowname=Label1 label=labl];
By using this technique, you can read the value of any statistic that is created by any SAS procedure. You can then use these
values in subsequent computations in PROC IML. For example, if you want to standardize the y
vector, you can use the mean and standard deviation as computed by the UNIVARIATE procedure, as shown in the following statements:
mean = nValue1[2]; stddev = nValue1[3]; stdQ = (q - mean)/stddev;