Submitting SAS Statements


Calling a Procedure

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:

  1. Write the data to a SAS data set by using the CREATE and APPEND statements.

  2. Use the SUBMIT statement to call a SAS procedure that analyzes the data.

  3. Read the results of the analysis into SAS/IML matrices by using the USE and READ statements.

  4. Use the results in further computations.

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.

  1. 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.

  2. 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;
    

    Figure 10.1: Output from the UNIVARIATE Procedure

    The UNIVARIATE Procedure
    Variable: Q

    Moments
    N 14 Sum Weights 14
    Mean 5.86428571 Sum Observations 82.1
    Std Deviation 2.49387161 Variance 6.2193956
    Skewness 0.66401924 Kurtosis 0.34860956
    Uncorrected SS 562.31 Corrected SS 80.8521429
    Coeff Variation 42.5264343 Std Error Mean 0.66651522

    
    


  3. 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];
    

    Figure 10.2: Statistics Read into SAS/IML Vectors

    Statistics for q
    N 14
    Mean 5.8642857
    Std Deviation 2.4938716
    Skewness 0.6640192
    Uncorrected SS 562.31
    Coeff Variation 42.526434

    
    


  4. 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;