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
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:
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:
I thought that might be the case! Thank you! 🙂
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.
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.