BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rbettinger
Lapis Lazuli | Level 10

I have written a SAS/IML module to print a matrix using an optional parameter list. The module is quite simple:

proc iml ;
a={1 2 3, 4 5 6} ;

start print_mat( matrix= ) ;
print 'isSkipped=' (isSkipped( matrix )) ;
print 'isEmpty =' (isEmpty ( matrix )) ;
print 'matrix=' matrix ;
finish ;

run print_mat( a ) ;
run print_mat( matrix=a ) ;
quit ;

and it works for the first invocation of print_mat without the optional parameter syntax, but stumbles for the second invocation where the optional parameter list syntax is used. I do not understand why I get the following error message:

205 run print_mat( matrix=a ) ;
ERROR: (execution) Matrix has not been set to a value.
 
operation : = at line 205 column 22
operands : matrix, a
 
matrix 0 row 0 col (type ?, size 0)
 
 
a 2 rows 3 cols (numeric)
 
1 2 3
4 5 6
 
statement : RUN at line 205 column 1
206 quit ;
Why is 'matrix' considered to be an operand? Why is it considered to be empty?
The error message indicates that the input parameter, matrix, does not point to matrix a. What am I failing to understand about the optional parameter list syntax?
Dr. Wicklin has explained how to use the optional parameter list here: https://blogs.sas.com/content/iml/2015/02/02/detect-empty-module-params.html, and I have modeled my module after his example. Please help my poor neuron to comprehend my error. Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

If you do not have other questions, please close this thread.

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

Unlike a SAS macro, which supports both positional and keyword syntax, a SAS/IML function only supports positional parameters. You can't call the function by using

run print_mat( matrix=a );

only by using

run print_matrix(a);

 

When you use that syntax, SAS tries to evaluate the expression "matrix=a", which is a boolean matrix, so that it can pass the appropriate matrix to the function.  However, there is no variable named 'matrix', so the expression "matrix=a" results in an error.  It's the same error you will get if you run

y = (matrix=a);

rbettinger
Lapis Lazuli | Level 10

Thank you for an informative reply. I misunderstood the syntax in the example contained in the webpage that I cited and thought that I could use the optionality of a parameter the same way that I can use a SAS/Macro keyword parameter.

Rick_SAS
SAS Super FREQ

If you do not have other questions, please close this thread.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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