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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Multiple Linear Regression in SAS

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.

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