SAS Interactive Matrix Language

SAS/IML is an interactive programming environment. It consists of a matrix programming language with rich in control structures, a powerful set of operators and a wide variety of functions. The software also offers integrated graphics, dataset processing and programmable windowing capabilities. SAS/IML applications can be run either interactively or in batch.
  • Summary of Features
    • Control Structures
      Control structures include conditional statements, iterative statements, and modular programming statements. Control statements direct the flow of execution of the other statements in IML. The control statements in IML work similarly to those in other programming languages (such as the SAS DATA step). The control statements are
      • GOTO, LINK
      • PAUSE, RESUME
      • STOP, ABORT
      • IF-THEN...ELSE
      • DO...END
      • START...FINISH
      • RUN
      • RETURN

    • Matrix Operators
      IML provides prefix, postfix, and infix operators to be used in expressions involving matrices.
       Addition: +                Element Power: ##
       Sign Reverse: -            Comparisons: < > =  <= >= ^=
       Subtraction: -             Element Maximum: <>
       Index Creation: :          Element Minimum: ><
       Matrix Multiplication: *   Horizontal Concatenation: ||
       Element Multiplication: #  Vertical Concatenation: //
       Direct Product: @          Logical Operators: & | ^
       Division: /                Transpose: `
       Matrix Power: **           Subscripts: []
      
       Subscript Reduction Operators
            Reduction operators can be used in place of values in 
            subscripts  to get reductions across all rows and/or 
            columns. Eight operators are available in IMLsubscript 
            reduction:  
            +     addition
            #     multiplication
            <>    maximum
            ><    minimum
            <:>   index of maximum
            >:<   index of minimum
            :     mean
            ##    sum of squares
    • Graphics Commands
      • GBLKVP: defines blanking viewport
      • GBLKVPD: deletes the blanking viewport
      • GCLOSE: closes the graphics segment
      • GDELETE: deletes a graphics segment
      • GDRAW: draws a polyline
      • GDRAWL: draws individual lines
      • GGRID: draws a grid
      • GINCLUDE: includes a graphics segment
      • GOPEN: opens a graphics segment
      • GPIE: draws pie slices
      • GPIEXY: converts from polar to world coordinates
      • GPOINT: marks a point
      • GPOLY: fills a polygon
      • GPORT: changes the viewport
      • GPORTPOP: pops the viewport
      • GPORTSTK: stacks the viewport
      • GSCALE: gets round numbers for labeling axis
      • GSCRIPT: writes with fonts
      • GSET: sets attribute for a graphics segment
      • GSHOW: shows the graph
      • GSTART: initializes graphics
      • GSTOP: stops graphics
      • GSTRLEN: finds the string length
      • GTEXT: places text horizontally on the graph
      • GVTEXT: places text vertically on the graph
      • GWINDOW: defines the data window
      • GXAXIS: draws a horizontal axis
      • GYAXIS: draws a vertical axis

    • SAS Dataset Processing Commands
      • USE: opens a dataset for read access
      • EDIT: opens a dataset for editing
      • CREATE: opens a new dataset
      • CLOSE: closes a dataset
      • SETIN: selects an open dataset for input
      • SETOUT: selects an open dataset for output
      • SHOW: shows status or contents of the open datasets
      • RESET: RESET DEFLIB sets the default libname
      • LIST: lists observations
      • READ: reads data into IML variables
      • REPLACE: writes data back into a dataset
      • APPEND: adds records to the end of the dataset
      • FIND: finds records satisfying a condition
      • DELETE: marks records for deletion
      • PURGE: purges deleted records
      • INDEX: indexes dataset variables

    • External File I/O Commands
      • INFILE: opens or sets a file for input
      • INPUT: inputs records, reading values into IML variables
      • FILE: opens or sets a file for output
      • PUT: outputs records, writing values of IML variables
      • CLOSEFILE: closes a file
      • SHOW FILES: displays status of all open files

    • Programmable Windowing Capabilities
      You can use IML to create windows on your display for full- screen data entry or menuing.
      • WINDOW: defines a window, its fields and attributes
      • DISPLAY: displays a window and awaits data-entry
      You can write applications using these statements that behave similar to other full-screen facilities in the SAS system such as AF and FSEDIT; however IML provides more flexibility in their programming.

    • Library Storage Commands
      IML's library storage features enable you to store matrices and user-defined modules in a special library storage. This is especially useful to save work from one session for use in another.
      • LOAD: load matrices or modules from the library
      • REMOVE: remove matrices or modules from the library
      • RESET USERLIB: set the user storage library
      • SHOW USERLIB: show the contents of the user storage library
      • STORE: store matrices or modules in userlib

    • Miscellaneous Commands and Functions
      • CONTENTS: return contents of a dataset
      • DATASETS: return list of datasets in a library
      • DELETE: delete a SAS dataset
      • EXECUTE: execute a statement immediately
      • FREE: free a matrix of its value
      • MATTRIB: associate print attributes
      • PGRAF: produce line printer graphs
      • PRINT: print values suitable for reports
      • PUSH: push lines to the input command stream
      • QUEUE: queue lines to the input command stream
      • RENAME: rename a SAS dataset
      • SORT: sort a SAS dataset
      • SOUND: generate a note with given frequency
      • SPLINE: spline routines for x-y data
      • SUMMARY: produce summary statistics for a SAS dataset

  • Built-in Functions
    A variety of mathematical and statistical functions are built directly into the software.
    • Scalar Functions
      • ABS: absolute value
      • EXP: exponential
      • INT: truncates to integer value
      • LOG: natural logarithm
      • MOD: modulo (remainder)
      • NORMAL: normal random number
      • SQRT: square root
      • UNIFORM: uniform random number
    • Reduction Functions
      • MAX: maximum value in a matrix
      • MIN: minimum value in a matrix
      • SSQ: sum of squares of all elements
      • SUM: sum of all elements
    • Matrix Inquiry Commands and Functions
      • ALL: checks for all elements nonzero
      • ANY: checks for any nonzero element
      • LOC: finds nonzero elements of a vector
      • NCOL: finds number of columns
      • NLENG: gets the length of a character element
      • NROW: finds the number of rows
      • TYPE: type of a matrix
    • Matrix Arithmetic Functions
      • CUSUM: cumulative sum
      • HDIR: horizontal direct product
      • TRACE: sum of diagonal elements
    • Matrix Manipulation and Reshaping
      • BLOCK: creates block diagonal matrix
      • BTRAN: computes block transpose
      • DIAG: creates square matrix from diagonal elements
      • I: creates an identity matrix
      • INSERT: inserts rows or columns
      • J: produces a matrix of identical values
      • REMOVE: removes elements
      • REPEAT: creates a matrix of repeated argument values
      • SHAPE: shapes a matrix
      • SQRSYM: converts symmetric to square
      • SYMSQR: converts square to symmetric
      • T: produces the transpose
      • VECDIAG: creates a column vector from diagonal elements
    • Character Manipulation
      • BYTE: gets ASCII byte by number
      • CHANGE: changes substrings
      • CHAR: converts numeric to character
      • CHOOSE: chooses elements conditionally
      • CONCAT: performs elementwise concatenation
      • CSHAPE: reshapes by characters
      • LENGTH: finds lengths of elements
      • NAME: returns the names of arguments
      • NUM: converts character to numeric
      • ROWCAT: concatenates elements across a row
      • ROWCATC: ROWCAT with blank compression
      • SUBSTR: produces a substring
    • Set Functions
      • SETDIF: finds set difference
      • UNION: finds set union
      • UNIQUE: removes duplicates
      • XSECT: finds set intersection
    • Linear Algebraic and Statistical Functions
      • CVEXHULL: finds a set of planar points
      • DESIGN: creates design matrices
      • DESIGNF: creates full-rank design matrices
      • DET: computes the determinant
      • ECHELON: reduces matrix to row-echelon normal form
      • EIGEN: computes eigenvalues and eigenvectors
      • EIGVAL: computes eigenvalues
      • EIGVEC: creates a matrix with orthonormal eigenvectors
      • GENEIG: computes eigenvalues and eigenvectors for generalized eigenproblems
      • GINV: creates the generalized inverse
      • GSORTH: computes Gram-Schmidt orthonormal factorization
      • HALF: performs Cholesky decomposition
      • HERMITE: reduces a matrix to Hermite normal form
      • HOMOGEN: solves a homogeneous linear system
      • INV: produces the inverse
      • INVUPDT: updates a matrix inverse
      • IPF: performs an iterative proportional fit
      • LCP: solves a linear complementarity problem
      • LP: solves a linear program
      • MARG: evaluates marginal totals in a multiway contingency table
      • ORPOL: generates orthogonal polynomials
      • POLYROOT: finds zeros of a real polynomial
      • PRODUCT: multiplies matrices of polynomials
      • RANK: performs ranking
      • RANKTIE: performs ranking with ties averaged
      • RATIO: divides matrices of polynomials
      • ROOT: performs Cholesky decomposition
      • SOLVE: solves a system of linear equations
      • SVD: performs singular value decomposition
      • SWEEP: performs sweep function
    • Time Series Functions
      • ARMACOV: computes autocovariance sequence for an ARMA model
      • ARMALIK: computes log likelihood and residuals for an ARMA model
      • ARMASIM: simulates a univariate ARMA time series
      • COVLAG: computes autocovariance estimates for time series
      • FFT: performs a finite Fourier transformation
      • HANKEL: generates a Hankel matrix
      • IFFT: performs an inverse finite Fourier transformation
      • TOEPLITZ: generates a Toeplitz matrix or block Toeplitz matrix
    • Numerical Analysis Functions
      • ODE : solves ordinary differential equations
      • QUAD : performs numerical integration
      • NLP : nonlinear optimization routines

  • Syntax
       PROC IML;            /* enters the SAS/IML procedure */
         ...
         ...
         SAS/IML programming statements
         ...
         ...
       QUIT;                /* exits the SAS/IML procedure  */
    

  • Alphabetical Index of Commands and Functions
    1. abort ab all any append apply armacov armalik armasim
    2. block branks btran byte
    3. call change choose close closefile concat contents convmod covlag create cshape cusum cvexhull
    4. datasets delete delete() design designf det diag display do() do/end do/loop do/data do/until do/while schar
    5. echelon edit eigen eigval eigvec execute exp
    6. fft file find free
    7. gblkvp gblkvpd gclose gdelete gdraw gdrawl geneig ggrid ginclude ginv gopen goto gpie gpiexy gpoint gpoly gport gportpop gportstk gscale gscript gset gshow gsorth gstart gstop gstrlen gtext gwindow gxaxis
    8. half hankel hdir hermite homogen
    9. i if/then ifft index infile input insert int inv invupdt ipf
    10. j jroot
    11. lcp length link list load loc log lp
    12. marg mattrib max maxqform min mod
    13. name ncol nleng nlp* normal nrow num
    14. ode opscal orpol ortvec
    15. parse pause pgraf polyroot print product purge push put
    16. qr quad queue quit
    17. rank ranktie ratio rdodt read rename remove remove() repeat replace reset resume return root rowcat rowcatc run rupdt
    18. save setdif setin setout shape show solve sort sound spline splinec splinev sqrsym sqrt ssq start stop storage store substr sum summary svd sweep symsqr
    19. toeplitz trace type
    20. uniform union unique use
    21. valset value vecdiag
    22. window
    23. xmult xsect

  • Alphabetical Index of Module Library
       COLVEC   :  returns a matrix as a column vector
       CORR     :  computes correlation coefficients
       GBXWHSKR :  box-whisker plot for a vector
       GPROBCNT :  probability contours for any x y data
       GXYPLOT  :  scatter plot of any x y data
       MEDIAN   :  returns medians of columns of matrix x
       QUADREG  :  quadratic response surface regression
       QUARTILE :  returns quartiles of columns of matrix x
       REGRESS  :  regression analysis
       ROWVEC   :  returns a matrix as a row vector
       RSUBSTR  :  replaces substrings
       STANDARD :  returns standardized data
       TABPRT   :  tabular printing of matrix x
    

JZone.com 2000