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.

92 JSL Building Blocks Chapter 5<br />

Compare Incomplete or Mismatched Data<br />

Suppose that your data table shows the discount percentage for purchases of $25, $50, $75, and $100. You<br />

want to create a graph that shows the discount for a $35 purchase, which the data table does not specify.<br />

The following example shows the value that you want to evaluate, 35, followed by matrices for purchases<br />

from $25 to $100.<br />

Step(35, [25 50 75 100], [5 10 15 25]);<br />

returns:<br />

5<br />

If the discounts were on a sliding scale (in this example, between 5 and 10, you would use Interpolate():<br />

Interpolate(35, [25 50 75 100], [5 10 15 25]);<br />

returns:<br />

7<br />

As with Interpolate(), the data points must create a positive slope.<br />

Compare Incomplete or Mismatched Data<br />

Comparing data that contains missing values can return misleading results unless you specify a condition<br />

that is always true or use functions such as IsMissing() or ZeroOrMissing(). Comparisons of data with<br />

mismatched types (numeric versus character) or data in matrices can also be confusing.<br />

Table 5.4 shows examples of such comparisons and matrices and explanations of the results. For a review of<br />

operators used in comparisons, see “Operators” on page 75. The sections that follow the table provide more<br />

details about comparison and logical operators.<br />

Note: Matrices must include the same number of columns or rows.<br />

Table 5.4 Some Special-Case Comparison Tests<br />

Test Result Explanation<br />

m=.; m==1 . An equality test with a missing value returns missing.<br />

m=.; m!=1 . An inequality test with a missing value returns missing.<br />

m=.; m1; and so<br />

on<br />

. A comparison with a missing value returns missing (unless it<br />

could not possibly be true, see next).<br />

m=.; 1

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

Saved successfully!

Ooh no, something went wrong!