I was surprised recently to get a "Matrix has not been set to a value" error when attempting to assign an empty matrix using VALSET. If the syntax
x = {};
is acceptable, should it not be possible to do the same thing indirectly? For example,
call valset('x', {});
will generate the error referred to above. My actual code is more complex, where the 2nd argument to VALSET is a function that might occasionally return an empty matrix, so I have simplified things above to illustrate the point. I am using SAS/IML 15.1.
You are correct. I do not have a workaround when the name of the symbol is not known until run time, since the FREE statement requires a symbol name, not a character string.
My only suggestion is to ask whether the function can return a missing value instead of an empty matrix. In my work, I often use a missing value to indicate an operation failed. It is easier to work with than an empty matrix.
Thanks for your reply Rick. I am still experimenting with Lists in IML, and I am using ListGetAllNames() which returns an empty matrix if there are no names associated with the list items. I am sure I will find a workaround.
IsEmpty(x) could detect if x is empty .
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.