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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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