Submitting SAS Statements


Handling Errors in a SUBMIT Block

After executing a SUBMIT block, PROC IML continues to execute the remaining statements in the program. However, if there is an error in the SUBMIT block, it might make sense to abort the program or to handle the error in some other way.

The OK= option in the SUBMIT statement provides a limited form of error handling. If you specify the OK= option, then PROC IML sets a matrix to the value 1 if the SUBMIT block executes without error. Otherwise, the matrix is set to the value 0.

The following statements contain an error in a SUBMIT block: two letters are transposed when specifying the name of a data set. Consequently, the isOK matrix is set to 0, and the program handles the error.

DSName = "Sashelp.calss";   /* mistyped name; data set does not exist */

submit DSName / ok=isOK;
proc univariate data=&DSName;
   var Height;
   ods output Moments=Moments;
run;
endsubmit;

if isOK then do;           /* handle the no-error case */
   use Moments;
   read all var {"nValue1"} into m;
   close Moments;
   skewness = m[4];        /* get statistic from procedure output */
end;
else
   skewness = .;           /* handle an error */

print skewness;

Figure 11.9: The Result of Handling an Error in a SUBMIT Block

skewness
.