BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jan_t_lagen
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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:

1. Video about calling SAS procedures from SAS/IML

2. SAS/IML documentation

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

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:

1. Video about calling SAS procedures from SAS/IML

2. SAS/IML documentation

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Rick_SAS
SAS Super FREQ

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 1408 views
  • 0 likes
  • 3 in conversation