BookmarkSubscribeRSS Feed
IanWakeling
Barite | Level 11

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.

3 REPLIES 3
Rick_SAS
SAS Super FREQ

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.

IanWakeling
Barite | Level 11

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.

Ksharp
Super User

IsEmpty(x)  could detect if x is empty .

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 3 replies
  • 1190 views
  • 2 likes
  • 3 in conversation