BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal23
Lapis Lazuli | Level 10

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

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

Bal23
Lapis Lazuli | Level 10

do until(w<1e-3);                     I still do not understand why w is used, why 1e-3 is used

 

Rick_SAS
SAS Super FREQ

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 852 views
  • 0 likes
  • 2 in conversation