Statistical programming, matrix languages, and more

sas iml basic

Accepted Solution Solved
Reply
Super Contributor
Posts: 336
Accepted Solution

sas iml basic

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.


Accepted Solutions
Solution
‎05-24-2016 08:42 AM
SAS Super FREQ
Posts: 3,477

Re: sas iml basic

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


All Replies
Solution
‎05-24-2016 08:42 AM
SAS Super FREQ
Posts: 3,477

Re: sas iml basic

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

Super Contributor
Posts: 336

Re: sas iml basic

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

 

SAS Super FREQ
Posts: 3,477

Re: sas iml basic

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

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 290 views
  • 0 likes
  • 2 in conversation