SAS/IML Software and Matrix Computations

Statistical programming, matrix languages, and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
imamathgk
Calcite | Level 5

Hi!

 

I am new to proc iml (and SAS in general) and am attempting to use proc iml optimization. Unfortunately, I am having trouble referencing a matrix that I created. The idea of my code is below:

 

proc iml;

use mysasdataset;

read all var into VARS;

close mysasdataset;

concent = VARS[,1];

print concent;

show names;

start F_HRCOPT(x);

     f=concent*matrix  (some other stuff follows here; the matrix to which I refer is 1x1).

     return f;

finish F_HRCOPT;

...continue with code...

 

The issue that I'm having is that when I use "show names;" it does state that the variable concent has been created and that its dimensions are Nx1 (which is exactly what I want; picture attached).  However, when I look at my SAS log it indicates that concent is empty (0x0). Any ideas why? Do I have to reference the matrix in a special way inside of the function? My thoughts are that the matrix "concent" should be a global matrix since it's defined outside of the function, which leads me to believe that I should be able to reference it inside of the function. Any insight would be greatly appreciated.

 

Thank you!!

 

JMM


undefined
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The problem is that SAS/IML functions use a local symbol table, so although the CONCENT matrix is known in the main (parent) environment, that symbol is not known to the function.  For a more comprehensize explanation, see the article "Understanding local and global variables in the SAS/IML language."

 

In short, you must pass in matrices to function via the argument list of declare them to be a global variable by using the GLOBAL clause.

 

If you intend to do some optimization in SAS/IML, I recommend the following articles:

 

You might also want to keep this documentation handy:

 

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

The problem is that SAS/IML functions use a local symbol table, so although the CONCENT matrix is known in the main (parent) environment, that symbol is not known to the function.  For a more comprehensize explanation, see the article "Understanding local and global variables in the SAS/IML language."

 

In short, you must pass in matrices to function via the argument list of declare them to be a global variable by using the GLOBAL clause.

 

If you intend to do some optimization in SAS/IML, I recommend the following articles:

 

You might also want to keep this documentation handy:

 

imamathgk
Calcite | Level 5

I thought that might be the case! Thank you! 🙂

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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