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
Opal | Level 21

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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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
  • 1051 views
  • 6 likes
  • 3 in conversation