Interpreting PROC IML error messages: Matrices do not conform to the operation


When learning a new language, it is important to learn to interpret error messages that come from the language's parser or compiler. Three years ago I blogged about how to interpret SAS/IML error messages. However, many questions have been posted to the SAS/IML Support Community that indicate that some people are confused about a common error message. The message is:

ERROR: (execution) Matrices do not conform to the operation.

Matrices that conform to operations

Recall that when you add, subtract, or multiply matrices, the dimensions of the matrices must satisfy certain conditions. Otherwise, the matrix operation is not defined. Let A and B be matrices.

  • For addition and subtraction, the operations A+B and A–B are defined only if the number of rows of A equals the number of rows of B, and the number of columns of A equals the number of columns of B. For example, if A is a 5 x 3 matrix, then B must have the same dimensions.
  • For the matrix multiplication A*B to make sense, the number of columns of A must be the same as the number of rows of B. For example, if A is a 5 x 3 matrix, then B must have three rows.
  • The horizontal concatenation operation A || B makes sense only when the number of rows of A equals the number of rows of B.
  • The vertical concatenation operation A // B makes sense only when the number of columns of A equals the number of columns of B.

When the matrices have dimensions that permit them to be added, we say that the matrices conform to the addition operation. When the matrices can be multiplied, we say that the matrices conform to the rules of matrix multiplication, and similarly for other operations.

Matrices that do not conform to an operation

If you try to operate on two matrices whose dimensions are not compatible, the SAS/IML language issues an error. If you look in the SAS Log, you will see the error message, followed by a message that provides the operation that caused the error and the dimensions of the matrices involved. For example, the following example tries to add a 1 x 3 matrix and a 2 x 2 matrix, which causes an error:

proc iml;
A = {1 2 3};
B = {4 5,
     6 7};
C = A + B;    /* causes an error */

The SAS Log contains the following information:

1    proc iml;
2    A = {1 2 3};
3    B = {4 5,
4         6 7};
5    C = A + B;
ERROR: (execution) Matrices do not conform to the operation.
 operation : + at line 5 column 7
 operands  : A, B
A      1 row       3 cols    (numeric)
         1         2         3
B      2 rows      2 cols    (numeric)
         4         5
         6         7
 statement : ASSIGN at line 5 column 1

The Log contains information about the error:

  • The ERROR occurred during execution. There are matrices that do not conform to some operation.
  • The operation that generated the error is the addition operator (+), which is located on line 5 and column 7 of the SAS Log.
  • The two matrices involved (the operands) are named A and B.
  • The matrix A is a 1 x 3 matrix. For small matrices, the matrix values are displayed in the Log.
  • The matrix B is a 2 x 3 matrix.

From that information and from your knowledge of the rules of matrix addition, you can conclude that the expression A + B is not well-defined for these matrices because then have different dimensions.

By understanding this example, you ought to be able to track down the source of other errors that result from attempting matrix operations on nonconforming matrices. However, be aware that the SAS/IML language accepts a "shorthand notation" for row and column operations that arise often in practice, even though the matrices are not conformable in a strict mathematical sense.


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.


  1. Peter Lancashire on

    Thanks, that's very helpful information, but shouldn't it be in the help? I tried searching for "Matrices do not conform to the operation" in the help (v9.2) and found nothing. I browsed and found a page which describes in general terms possible errors in IML but it does not contain the text of the error message so you can't search for it. This is my usual frustrating experience with SAS messages: they are not in the help.

    Other software products I have used have catalogued ALL error messages by number and text and provided an entire book of explanations and tips about what to do. I find this very helpful. It should be done for all software: the programmers wrote the error messages so I assume they know what they mean.

    SAS could improve the quality of its documentation by including the text of ALL error and warning messages with the sort of helpful information you have written in this blog. How do we get action on this?

    • Rick Wicklin

      That is a good idea. I wish that error messages were written so clearly that they would be self-documenting.

      I won't defend the status quo, but I will mention a few relevant points to let you know why your suggestion is a big job. SAS has many thousands of error messages, most of which occur only rarely. Furthermore, some error messages are issued by subroutines in a math or utility library that is used by dozens of procedures, so it's not clear where to document those messages. Furthermore, error messages are translated into dozens of local languages (German, Japanese, Chinese, Russian, etc), so a Web search would only help the English speakers.

      I will look into adding a section of the SAS/IML doc that describes common error messages that arise in practice. In my experience, there are 10-12 that appear 90% of the time, so that seems like a good place to start.

      To answer your last question, SAS has a user-feedback ballot for software improvements that is read by developers. You might suggest your idea to the "SAS Procedures" community.

  2. Pingback: How to coerce SAS/IML vectors to matrices - The DO Loop

Leave A Reply

Back to Top