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


Screen Shot 2016-12-07 at 11.17.02 AM.png
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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 1083 views
  • 0 likes
  • 2 in conversation