Hi
I just started to study SAS iml. it is hard for me to understand
would anybody explain.
do until(w<1e-3); /* begin do loop */
my questions: why is it used? Why "w" and "1e-3"?
y = 0.5#(z + x/z); * Estimate square root;
my questions: Why it is written like that? But not: y = 0.
5#z or 0.5#x
I do not understand it
would you please give advice that helps me to understand? Thanks.
The DO UNTIL syntax is not special to SAS/IML. In SAS, a DO UNTIL loop iterates until a certain condition is met. In this case, iterate until the w variable is smaller than 0.001. The formula for y is equivalent to the more familiar DATA step syntax
y = 0.5*(z + x/z);
or
y = (z + x/z)/2;
To learn more about SAS/IML syntax, see the second and third tips in the article "Ten tips for learning the SAS/IML language."
The DO UNTIL syntax is not special to SAS/IML. In SAS, a DO UNTIL loop iterates until a certain condition is met. In this case, iterate until the w variable is smaller than 0.001. The formula for y is equivalent to the more familiar DATA step syntax
y = 0.5*(z + x/z);
or
y = (z + x/z)/2;
To learn more about SAS/IML syntax, see the second and third tips in the article "Ten tips for learning the SAS/IML language."
do until(w<1e-3); I still do not understand why w is used, why 1e-3 is used
To answer your question we would need to see the whole program. You did not provide any context or link to the source of your question.
It looks like the basis of your question is an example in the SAS/IML documentation. In the example, w measures the change between the old and new values in an iterative algorithm. The author wants to stop the algorithm when the i_th iterate is within 0.001 of the (i-1)th iterate. If you wanted greater precision, you could say
do until(w < 1e-6);
Incidentally, to better undertstand the algorithm see the article "The Babylonian method for finding square roots by hand."
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.