14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

84 JSL Building Blocks Chapter 5<br />

Iterate<br />

y *= 2<br />

Multiplies 1 by 2 and then assigns the result to y. The loop then<br />

repeats while y is less than 287.<br />

); Ends the loop.<br />

Show(y); Shows the value of y (512).<br />

// loop 2<br />

k = 0; Sets k to 0.<br />

While(<br />

Begins the While() loop.<br />

2 ^ k < x, Raises 2 to the exponent power of k and continues evaluating<br />

the loop as long as the result is less than 287.<br />

k++<br />

Increments k to 1. The loop then repeats while 2 ^ k is less than<br />

287.<br />

); Ends the loop.<br />

Show(2 ^ k); Shows the value of 2 ^ k (512).<br />

As with For() loops, Which() loops that always evaluate as true create an infinite loop, which never stops.<br />

To end the loop as the script runs, press ESC on Windows (or COMMAND-PERIOD on Macintosh).<br />

Summation<br />

The Summation() function adds the body results over all i values. The syntax is:<br />

Summation(initialization, limitvalue, body);<br />

For example:<br />

s = Summation(i = 1, 10, i);<br />

returns 55, the result of 1+2+3+4+5+6+7+8+9+10.<br />

The script works like this:<br />

s =<br />

Summation(<br />

Sets the s variable to the value of the function.<br />

Begins the Summation() loop.<br />

i = 1, Sets i to 1.<br />

10, Sets the limit of i to 10.<br />

i All values of i from 1 to 10 are added together, resulting in 55.<br />

); Ends the loop.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!