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

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:, and I have modeled my module after his example. Please help my poor neuron to comprehend my error. Thanks!



Accepted Solutions

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

View solution in original post


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);

Pyrite | Level 9

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.


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



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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
  • 1 like
  • 2 in conversation