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.

90 JSL Building Blocks Chapter 5<br />

Conditional Functions<br />

Choose<br />

The Choose() function shortens scripts even more than Match(), provided the arguments are tested<br />

against integers. The syntax is:<br />

Choose(expr, result1, result2, result3, ..., resultElse)<br />

Suppose you have a data table with a column of numeric values from 1 through 7. If the first cell contains<br />

the number 1, the following script returns x = "Low".<br />

x = (Choose(group,<br />

"Low",<br />

"Medium",<br />

"High",<br />

"Unknown"<br />

);<br />

);<br />

Show(x);<br />

The script works like this:<br />

x =<br />

Choose(<br />

group,<br />

"Low",<br />

"Medium",<br />

"High",<br />

"Unknown"<br />

Creates the x variable.<br />

Begins the Choose() loop.<br />

Evaluates the value of group.<br />

If the value of group is 1, return "Low".<br />

If the value of group is 2, return "Medium".<br />

If the value of group is 3, return "High".<br />

Otherwise, return "Unknown".<br />

) Ends the loop.<br />

); Closes the x variable.<br />

Show(x); Returns the value of x.<br />

If the expression evaluates to an out-of-range integer (such as 7 when only 4 replacement values are listed),<br />

the last result is returned. In the preceding example, "Unknown" is returned.<br />

Notice that If() and Match() require more code to achieve the same results as the Choose function:<br />

if(group==1, "Low", group==2, "Medium", group==3, "High", "Unknown");<br />

match(group, 1, "Low", 2, "Medium", 3, "High", "Unknown");<br />

Note: If the data types in the expression do not match, JMP automatically changes the column’s data type.

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

Saved successfully!

Ooh no, something went wrong!