Getting Started With the SAS/IML® Language a High-Level Matrix Programming Language
July 17, 2026 · 745 KB
Converting five temperatures from Celsius to Fahrenheit takes one line and no loop in SAS/IML. This 2013 SAS Global Forum workshop paper introduces the matrix language to SAS programmers.
Overview
One line of SAS/IML code converts a whole vector of temperatures from Celsius to Fahrenheit, with no loop. The code looks just like the formula. That example opens this hands-on workshop paper, number 144-2013, by Rick Wicklin of SAS Institute for SAS Global Forum 2013. It is based on Chapters 2–4 of his 2010 book on SAS/IML.
What IML Is
IML stands for "interactive matrix language." The paper is aimed at SAS programmers who know basic linear algebra and need statistics that no SAS procedure computes. It contrasts the language with the DATA step. A DATA step loops over observations and reads and writes data sets. A SAS/IML program works on whole matrices kept in memory. The author stresses vectorizing code: use built-in functions and matrix operations, and avoid loops over single elements.
Running Programs
The paper explains how to run programs in PROC IML or SAS/IML Studio. It warns that SAS Enterprise Guide adds a QUIT statement to each submission, which deletes all computed matrices. It then covers creating matrices, extracting and assigning submatrices with subscripts, and reading SAS data sets into matrices and writing results back.
Modules
Later sections show how to write modules, user-defined functions that begin with START and end with FINISH. One example standardizes the columns of a matrix. Variables inside a module are local unless a GLOBAL clause shares them. The paper also shows how to call SAS procedures from within a program and how to simulate data.
A Worked Example
The final example fits a normal curve to sepal widths in the classic iris data set. The exact maximum likelihood estimates are compared with a Newton-Raphson optimization, which reaches the same values within less than one millionth.
Why It Matters
It offers a compact starting point for SAS users who need to build custom statistical calculations.
