BookmarkSubscribeRSS Feed
Ioana
Calcite | Level 5

Hello,

I am new to SAS and I would like to know how to tweak this program to break the infinite do until loop. At the end of the do until loop I would like to be able to print the updated phi. Thanks.

4 REPLIES 4
Astounding
PROC Star

With any DO UNTIL loop, it is possible that it never ends because the UNTIL condition never becomes true.  In your case, this condition might never become true:  (n < 0.001)

One way to guard against it is to allow two ways for the loop to end:

do k=1 to 100000 until (n < 0.001);

If the loop iterates 100,000 times, it will end regardless of the value of n.  Your subsequent statements might have to allow for the possibility that n > 0.001.  The loop will end before 100,000 iterations if the UNTIL condition becomes true.

Good luck.

Ioana
Calcite | Level 5

Thank you so much.

Rick_SAS
SAS Super FREQ

Welcome to SAS!  To break the infinite DO UNTIL loop, I often include a maximum number of iterations, like this:

maxIter = 50;

iter = 0;

do until(n<0.001 | iter>=maxIter);

   /* computations */

   n = sqrt(direc[##]);

   iter = iter + 1;

end;

If I might offer another suggestion, your computation is looping over the I variable 50,000 times and updating elements of vectors. It might be possible for you to eliminate that loop. For ideas, see

http://blogs.sas.com/content/iml/2013/05/15/vectorize-computations/

Ioana
Calcite | Level 5

Thank you so much.

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
  • 4 replies
  • 1187 views
  • 6 likes
  • 3 in conversation