A SAS programmer asked for a list of SAS/IML functions that operate on the columns of an n x p matrix and return a 1 x p row vector of results. The functions that behave this way tend to compute univariate descriptive statistics such as the mean, median, standard deviation, and quantiles.

The following SAS/IML functions compute a statistic for each column of a matrix:

• COUNTMISS function: counts the number of missing values (use the "col" option)
• COUNTN function : counts the number of nonmissing values (use the "col" option)
• COUNTUNIQUE function: counts the number of unique values (use the "col" option)
• CV function: computes the sample coefficient of variation
• KURTOSIS function: computes the sample kurtosis
• MAD function: computes the univariate median absolute deviation
• MEAN function: computes sample means
• QNTL call: computes sample quantiles (returns multiple rows)
• QUARTILE function: computes the five-number summary (returns five rows: min, Q1, Q2, Q3, and max))
• SKEWNESS function: computes the sample skewness
• STD function: computes the sample standard deviation
• VAR function: computes the sample variance

You can also use subscript reduction operators to compute the following descriptive statistics for each column in a matrix X:

• X[+, ] returns the column sums (similar to the SUM function)
• X[#, ] returns the column products (similar to the PROD function)
• X[<>, ] returns the column maxima (similar to the MAX function)
• X[><, ] returns the column minima (similar to the MIN function)
• X[<:>, ] returns the index of the column maxima
• X[>:<, ] returns the index of the column minima
• X[##, ] returns the column sum of squares (similar to the SSQ function)

Lastly, elementwise operators (+, -, #, /, ##) in SAS/IML can operate on columns.

Share Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of PROC IML and SAS/IML Studio. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.

1. • 