This might be a long and stupid question...My goal is to either find a way to do what i want or understand why I can't/shouldn't do it.
I'm working on a project where I need to include some data steps inside a loop that I have created using IML.
The reason for this is that i need to manipulate the data by joining, inserting new variables and summing in order to reduce the size of the matrix calculations. I also need to do this (in some way) within a loop as I'm sampling data for each iteration. Firstly, as I'm new to using IML, is there a reason why it is not possible to just insert a data step in the middle of my IML code? I don't think it would be impossible to recreate the steps I've done using IML but I'd rather not do it. Is there a way to do this?
To clarify I want something like this:
proc iml;
iter = 5;
do i=1 to iter;
/* proc surveyselect data...*/
/*data steps*/
/*import variables from last data step to vectors*/
/* matrix calculations */
end;
;quit;
It seems to work using a macro and looping outside i.e:
%macro func();
%do iter=1 %to 5;
/*data steps*/
proc iml;
/*import variables from last data step to vectors*/
/* matrix calculations */
;quit;
%end;
%mend;
%func();
I would like to avoid this however as it less similar to the method i'm trying to implement and not as intuitive (in a mathematical sense). And a more vain reason is that I hate that all the color coding disappears when working inside a macro... maybe this is removable?
thanks!
It sounds like you want to use the SUBMIT / ENDSUBMIT statements to call SAS procedures inside an IML loop.
I do this all the time. Some resources are:
It sounds like you want to use the SUBMIT / ENDSUBMIT statements to call SAS procedures inside an IML loop.
I do this all the time. Some resources are:
The reason for this is that i need to manipulate the data by joining, inserting new variables and summing in order to reduce the size of the matrix calculations
This can all be done in IML code. No need for a datastep here.
I also need to do this (in some way) within a loop as I'm sampling data for each iteration.
This can all be done in an IML loop
In addition to Paige's comment, I'll point out that some people try perform simulation or bootstrapping by using the technique that you suggest. This is a bad idea because it is not efficient. To read more about how to simulate data in SAS efficiently, see "The Slow Way or the BY Way."
If your intention is a simulation or a resampling technique such as the bootstrap, specify what you are trying to accomplish and we can help you implement it efficiently.
If you plan on doing several simulation or resampling studies, you might want to search or browse
https://blogs.sas.com/content/tag/simulation/
or
https://blogs.sas.com/content/tag/bootstrap-and-resampling/
The book Simulating Data with SAS also covers these topics in detail.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.