How to interpret SAS/IML error messages

6

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!

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.

6 Comments

  1. Pingback: How to find and fix programming errors - The DO Loop

  2. Pingback: Interpreting PROC IML error messages: Matrices do not conform to the operation - The DO Loop

  3. Eldho Varghese on

    Dear Dr. Rick,
    Please help me in solving the problem given below:
    proc iml;
    perm = 1:20;
    do i=1 to fact(20);
    perm = allperm(perm, i);
    print perm;
    end;
    quit;

    It gives an error message "ERROR: (execution) Invalid argument to function."

    But the same program gives result when

    proc iml;
    perm = 1:8;
    do i=1 to fact(8);
    perm = allperm(perm, i);
    print perm;
    end;
    quit;
    Is there any upper limit for "allperm"??????

    • Rick Wicklin

      1) Please ask programming questions at the SAS Support Communities
      2) The limit for all permutation functions in SAS is k=18. That is that largest value for which fact(k) < constant("exactint"). When k=20, you can't enumerate the permuations with an integer.

      On a related note, be glad that the program failed. You do NOT want to loop over (and print out!) 2.43e18 elements! You would be wise to limit your loops to less than a billion (1e9) iterations, and even loops that "small" are likely to take a long time.

  4. could you please help with my problem. i have the same error in my program as follows;
    ERROR: (execution) Invalid argument to function.

    count : number of occurrences is 219
    operation : LOG at line 16017 column 1
    operands : _TEM1002
    _TEM1002 253 rows 1 col (numeric)

    statement : ASSIGN at line 16017 column 1
    what should i do???

Leave A Reply

Back to Top