What is an empty matrix?

3

At the beginning of my book Statistical Programming with SAS/IML Software I give the following programming tip (p. 25):

Do not confuse an empty matrix with a matrix that contains missing values or with a zero matrix. An empty matrix has no rows and no columns. A matrix that contains missing values has at least one row and column, as does a matrix that contains zeros.

What do those sentences mean? Consider the following SAS/IML program:

proc iml;
z = j(2, 2, 0);       /* zero matrix = {0 0, 0 0} */
m = j(1, 4, .);       /* matrix of missing = {. . . .} */
q = {};               /* empty matrix */

The J function in SAS/IML software creates a matrix that has a specified number of rows and columns and fills the matrix with a constant value. The syntax is result = j(nrows, ncols, value). The first statement in the program creates a matrix named z that has two rows and two columns. Each element of the matrix has the value 0. The matrix is also called a "zero matrix." You can print this matrix and use it in expressions that involve matrix addition, matrix multiplication, logical expressions, and so forth.

The second statement creates a matrix named m that has one row and four columns. Each element is a missing value. The matrix is called a "matrix of missing values." You can print this matrix. You can use it in some elementwise matrix operations, but not in matrix multiplication.

The third statement creates an empty matrix. It has zero rows and zero columns. It does not have any elements. You cannot add with it, multiply with it, or even print it. However, you can ask for its dimensions, concatenate with it, and use it in set operations such as unions and intersections.

The syntax q = {} was introduced in SAS/IML 12.1. Read my previous article for ways to create and detect empty matrices.

In conclusion, do not confuse an empty matrix with a matrix of missing values. They are very different. The former has no rows or columns. The latter has rows and columns, but every element is a missing value.

Share

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. 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.

3 Comments

  1. Pingback: Detect empty parameters that are passed to a SAS/IML module - The DO Loop

  2. jeroen van beele on

    However, you can ..., concatenate with it,...

    i don't see how to do that, this is what i tried:

    27 proc iml;
    NOTE: IML Ready
    28 a = {};
    29 b = {1};
    30 c = a || b;
    31 print a, b, c;
    ERROR: Matrix a has not been set to a value.

    statement : PRINT at line 31 column 1
    32 quit;
    NOTE: Exiting IML.

Leave A Reply

Back to Top