BookmarkSubscribeRSS Feed
jhzeinab_yahoo_com
Calcite | Level 5

I have a very slow running simulation code that uses IML. Although I am generating 10,000 samples for every iteration, I need to retain the first sample record once a calculated T statistic is greater than h value.

The code is running extremely slow and I could get only one iteration per day. I appreciate any help or suggestions anyone can provide. SAS cod eis attached.

Thank you

3 REPLIES 3
IanWakeling
Barite | Level 11

That is very slow indeed.  I imagine most of the time spent by your program is either processing the macro code or opening/closing proc IML.  The latter you are doing around 50 million times which must bring a significant overhead.   I think you need to rewrite the program so that all of the iterations occur within IML - no macro loops at all, use only IML do loops.

Rick_SAS
SAS Super FREQ

I agree with Ian.

Your program is currently structured like this:

%DO loops: grid in (lambda, h) space

%DO simulation loop (10,000 iterations)

   call PROC IML

   write one observation

   call PROC APPEND to append obs

%END simulation

call PROC MEANS to get mean, std, and sterr of simulation with given (lambda, h)

%END grid loops

To make it more efficient, structure it like this:

call PROC IML

CREATE output var {lambda h mean std stderr}; /* open data for results */

DO loops: grid in (lambda, h) space

DO simulation loop (10,000 iterations)

   accumulate simulated data in rows of matrix

END simulation

Use SAS/IML functions (MEAN, STD,...) to get mean/std/stderr of simulation with given (lambda, h)

APPEND;  /* write results to data set */

END grid loops

jhzeinab_yahoo_com
Calcite | Level 5

Than you Ian and Rick. While I have been using SAS for over 25 years, I just started using IML a month or so ago. I will rewrite the macro within to only loop within IML. I will post my progress updates soon. Thank you again.

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