In SAS IML I would like to pass a variable number of matices of numeric and character types and different dimensions to a user defined module. This can be implemented by e.g. creating a list of objects and pass the list to the module. For instance in R such data type is just called "list". Similar functionality is implemented in matlab as cell list, and in C++ and Java by inheritance from an abstract class. Unfortunately can not find this in SAS IML documentation.
How can list of arbitrary objects be created in SAS IML?
Thanks a lot.
Alex
Rick, thank you for quick reply.
The idea with optional arguments is restricted in long-term, since I need to pass 2-or-more arguments, not 15-or-fewer.
Howevr the second idea inspired me for another workaroud.
Before calling the function I have list of matrix names
names = {A, B, C};
In a cycle I will create temporary datasets according to the names, and then pass the names to the function. Inside the function I will have all the datasets accessible. After call of the function I will delete them in a loop.
Hope this will not be computationally expensive, otherwise will have to resort to one of your ideas.
Thanks
SAS/IML does not support lists of matrices.
However, here are two ideas that might help you with your task. The first is to define your module to take optional arguments. You can call the module with an arbitrary number of matrices and the module can detect (by using the ISSKIPPED function) how many matrices you sent in. See the article "Define functions with optional parameters.") This is what I would choose if I have 15 or fewer matrices.
Here is how to implement the first idea:
Test the module by passing in three arguments of different sizes:
The second idea is to pack your numerical matrices into a large single matrix where the i_th row contains the values of the i_th matrix. This will support arbitrarily many matrices, but it is somewhat wasteful in terms of memory. First you need to figure out the maximum number of elements in the union of the matrices. Then allocate a matrix big enough to hold all the matrices. The VALUE function (see the article "Indirect assignment") will be helpful for automating this step:
The PACK matrix contains all the numerical data. (Do something similar for character matrices.) You can then send the DIM and PACK matrices to a module. The module can use the SHAPE function to unpack the matrices into their original shapes. For example, the following module unpacks the original matrices and prints them: