Errors. We all make them. After all, “to err is human.” Or, as programmers often say, “To err is human, but to really foul things up requires a computer” (Farmer’s Almanac, 1978). This post describes how to interpret error messages from PROC IML that appear in the SAS log.
The following example is adapted from Chapter 5 of Statistical Programming with SAS/IML Software. Suppose you run the following SAS/IML statements that contain a run-time error:
proc iml; do x = 5 to 1 by -1; y = log(x); z = log(y); end;
When you run the program, the following message appears in the SAS log:
1 proc iml; NOTE: IML Ready 2 do x = 5 to 1 by -1; 3 y = log(x); 4 z = log(y); 5 end; ERROR: (execution) Invalid argument to function. operation : LOG at line 4 column 11 operands : y y 1 row 1 col (numeric) 0 statement : ASSIGN at line 4 column 4
How can you interpret the error messages in order to determine what is wrong with the program? Let’s examine each line of the error message.
ERROR: (execution) Invalid argument to function.
This means that the error is that some function has received an invalid value for an argument. Which function? Which argument? We need to read on.
operation : LOG at line 4 column 11
Ah-ha! The function that encountered the error is the LOG function. Which LOG function? The one defined on Line 4, Column 11, of the SAS log. I quick look at the SAS log reveals that the statement on that line is z = log(y).
operands : y y 1 row 1 col (numeric) 0
This portion of the error message displays the operands (arguments) to the operation that encountered the error. In this case, the LOG function has a single argument, y. The error message tells us that at the time of the error, the matrix y had one row, one column, and was a numeric matrix with the value 0. When we combine this information with the fact that this error results from an invalid argument to the LOG function, we can conclude that the program is complaining that we have asked it to evaluate LOG(0), which is mathematically undefined.
statement : ASSIGN at line 4 column 4
This message says that the program could not complete the assignment statement at Line 4, Column 4. In other words, the program could not assign the z variable. No surprise there. That assignment is bound to fail if the LOG function cannot be evaluated.
So there you have it. The problem is that at some time during iteration of the DO loop, the value of y is zero. If you study the code, you can conclude that this occurs when x is 1.
To err is human, to debug, divine!