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.

As you might expect, many of these operations also apply to **rows** of a matrix if you make a minor modification. For example,
to count values across each row, use the "row" option of the COUNTMISS, COUNTN, and COUNTUNIQUE functions. To use subscript reduction operators on rows, change the location of the operator. For example,
X[ ,+] returns the row sums, and X[ ,##] returns the sum of squares for rows. Although the functions that compute descriptive statistics (CV, KURTOSIS, MAD, ...) do not have a row option, you can pass in the transpose of a matrix to operate on its rows.
M/p>

## 6 Comments

Rick,

You missed another way. SUMMARY statement .

OK, but that isn't a function that acts on a matrix. It is a statement that acts on a data set.

Pingback: The jackknife method to estimate standard errors in SAS - The DO Loop

Hi Rick

I am using SAS/IML. I have imported my data from excel into SAS using PROC IMPORT.

I want then to enable SAS interactive matrix language. I would like to save my data in a matrix. The matrix will depend in the data inserted in the excel file. Sometimes I have data over 5 columns and sometimes over 6 columns. Therefore I need to read how many columns I have in the excel file. Is this possible?

Thanks

It sounds like you want to read all the columns into a matrix. You can use the _NUM_ keyword to read all numeric variables into a matrix. (There is also a _CHAR_ keyword, which reads all character variables.) See "Read ALL variables INTO a matrix."

Pingback: Jackknife estimates in SAS - The DO Loop