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:
If you do not have other questions, please close this thread.
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);
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.
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!
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.