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 9 Data Tables 303<br />

Calculations<br />

Example<br />

Take advantage of this method to develop a compact formula to distinguish females and males with Xs and<br />

Ys, while excluding females from calculations, hiding males from plots, and assigning different colors for<br />

each age.<br />

Recall that the logical == operator is an equality test that returns 1 for true and 0 for false.<br />

dt=open("$SAMPLE_DATA/Big Class.JMP");<br />

for each row(<br />

rowstate() = as row state(<br />

(sex=="F")*2 + // exclude F<br />

(sex=="M")*4 + // hide M<br />

((sex=="F")*2+(sex=="M")*6) * 16 +<br />

// marker 2 for F, 6 for M<br />

(age-11)*256));<br />

// colors 1 through 6<br />

Calculations<br />

This section discusses functions for pre-evaluated columnwise and rowwise statistics and shows how JSL<br />

expressions work behind the scenes in the JMP formula calculator. See the earlier discussion of “Summarize”<br />

on page 252, for a way to gather summary statistics on a data table.<br />

Pre-Evaluated Statistics<br />

JMP has Col Maximum, Col Mean, Col Minimum, Col N Missing, Col Number, Col Quantile, CV<br />

(Coefficient of Variation), Col Standardize, Col Std Dev, Col Sum, Maximum, Mean, Minimum,<br />

NMissing, Number, Std Dev, and Sum functions, which are special “pre-evaluated” functions.<br />

Note: Statistics are also computed with Summarize (p. 252). Although the named arguments to<br />

Summarize have the same names as these pre-evaluated statistic functions, they are not calling the<br />

pre-evaluated statistic functions. The resemblance is purely coincidental.<br />

All the statistics are pre-evaluated. That is, JMP calculates them once over the rows or columns specified and<br />

thereafter uses the results as constants. Because they are computed once and then used over and over again,<br />

they are more efficient to use in calculations than an equivalent formula-calculated results.<br />

When JMP encounters a pre-evaluated function in a script, it immediately evaluates the function and then<br />

uses the result as a constant thereafter. Thus, pre-evaluated functions enable you to use columnwise results<br />

for rowwise calculations. For example, if you use Col Mean inside a column formula, it first evaluates the<br />

mean for the column specified and then uses that result as a constant in evaluating the rest of the formula on<br />

each row. For example, a formula might standardize a column using its preevaluated mean and standard<br />

deviation:<br />

(Height-Col Mean(Height))/Col Std Dev(Height)

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

Saved successfully!

Ooh no, something went wrong!