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.
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.
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;
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
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.
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.