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.

Chapter 5 JSL Building Blocks 91<br />

Conditional Functions<br />

Interpolate<br />

Step<br />

The Interpolate() function finds the y value corresponding to a given x value between two points (x1,<br />

y1 and x2, y2). A linear interpolation is applied to the values. You might use Interpolate() to calculate<br />

missing values between data points.<br />

The data points can be specified as a list:<br />

Interpolate(x, x1, y1, x2, y2, ...)<br />

or as matrices containing the x and y values:<br />

Interpolate(x, xmatrix, ymatrix)<br />

Suppose that your data set includes the height of individuals from age 20 through 25. However, there is no<br />

data for age 23. To estimate the height for 23-year-olds, use interpolation. The following example shows the<br />

value that you want to evaluate (age 23), followed by matrices for ages (20 through 25) and heights (59<br />

through 75).<br />

Interpolate(23, [20 21 22 24 25], [59 62 56 69 75]);<br />

returns:<br />

62.5<br />

The value 62.5 is halfway between the y values 56 and 69, just as 23 is halfway between the x values 22<br />

and 24.<br />

Notes:<br />

• The data points in each list or matrix must create a positive slope. For example,<br />

Interpolate(2,1,1,3,3) returns 2. However, Interpolate(2,3,3,1,1) returns a missing value<br />

(.).<br />

• Interpolate is best used for continuous data, but Step() is for discrete data. See “Step” on page 91<br />

for details.<br />

The Step() is like Interpolate() except that it finds the corresponding y for a given x from a<br />

step-function fit rather than a linear fit. Use Step() with discrete y values (that is, when the y value’s<br />

corresponding x value can be only y 1 or y 2 ). However, when the y value’s corresponding x value can fall<br />

between y 1 and y 2 , use Interpolate().<br />

As with Interpolate, the data points can be specified as a list:<br />

Step(x, x1, y1, x2, y2, ...)<br />

or as matrices containing the x and y values:<br />

Step(x, xmatrix, ymatrix)

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

Saved successfully!

Ooh no, something went wrong!