Enhancements to the SAS/IML Syntax

SAS/IML 12.1 includes the following enhancements to the syntax:

  • SAS/IML supports a new syntax that defines optional arguments and default parameter values for user-defined modules. These changes are described in the section Modules with Optional and Default Arguments. One implication of the new syntax is that you cannot omit a parameter when you call a user-defined subroutine unless the module definition explicitly specifies that the parameter is optional. This syntax change might require that you modify SAS/IML programs that parsed and ran without error in previous releases.

  • There is a new syntax for reading and writing SAS data sets that enables you to read data sets whose name is given by a run-time expression rather than by a literal value. For example, the following syntax is now valid:

    dsname = "Sashelp.Class";
    use (dsname);
    read all var _NUM_ into X;
    close (dsname);
    

    This syntax is equivalent to the following statements:

    use Sashelp.Class;
    read all var _NUM_ into X;
    close Sashelp.Class;
    

    This functionality is available in the CLOSE, CREATE, EDIT, SETIN, SETOUT, SORT, and USE statements. These changes are described in the section Syntax for Specifying a SAS Data Set.

  • You can now pass the same matrix into a module in several parameter locations. The first time that a variable is passed, it is passed by reference. Subsequent arguments receive a copy of the matrix. For example, the following syntax is now valid:

    start DotProduct(x,y);
       return( x`*y );
    finish;
    
    x = {1,2,3,4};
    z = DotProduct(x, x); /* pass the same matrix twice */
    
  • There is a new syntax for defining an assignment to an empty matrix. The statement x={}; is similar to using the FREE statement. This syntax can be used to specify that the default value of a module argument is the empty matrix.

In addition, SAS/IML 12.1 includes the following enhancements to functions, subroutines, and modules:

  • The RANDGEN subroutine now accepts vectors of parameters. These vectors can be used to fill a matrix with random values such that each column (or row) of the matrix is sampled from a different distribution.

  • The ROOT function now accepts an optional parameter that you can use to determine whether a matrix is positive definite.

  • The SUBSTR function now accepts any parameter as a vector. These vectors can be used to extract several substrings from a string with a single call.