If I understand your question, I believe the answer is yes. The caller would need to specify the COLNAME= and ROWNAME= options.
If the purpose of the module is to display the tables, why not do the printing inside the module? Then you can use the ROWNAME= and COLNAME= options to put nice headers on the output. This is the approach used by the regression module in the SAS/IML Getting Started example, which is very similar to your module.
Thank you! I modified my code and it worked. I appreciate all the help from the forum.
@Sanjana1 wrote:
I am trying to create a user defined function for multiple linear regression using proc iml. I am trying to create a function where I can input any SAS dataset and values from dataset would be read into two matrices - x for predictors and y for outcome. The matrices would then be used in the formulas for computing estimates for linear regression. But I keep getting an error that dataset doesnt exist. Any suggestions on what is wrong with the code? Also is it possible to input varying number of predictors and still get the function to work?
If you are getting errors in the log, then SHOW US the log. Simply telling us you are getting errors in the log is never sufficient.
May I ask why you want to do this, since SAS has put all the necessary effort to do these calculation into PROC REG? If it is an attempt to learn IML, then that's fine in my opinion; if you are trying to perform real work this way, I would say use PROC REG. SAS has done the hard work to make sure PROC REG gives the correct answer, SAS has thoroughly debugged and tested PROC REG and generally people don't question the results, whereas you would have to spend a lot of time to provide the same level of confidence in your IML code. In addition, PROC REG has a gazillion useful features that your IML code doesn't have.
I am trying to learn iml 🙂
In general, when someone posts a question to the IML Community, I think the experts should assume that the OP has a reason to want the operation in IML. There are many reasons for wanting to implement a routine that reproduces functionality that is also available in a SAS procedure. For example, linear regression might be one substep in a complicated iterative algorithm. Learning the language is another. Class programming assignments are a third.
If we have answered your questions, please mark this thread as ANSWERED.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.