eval Function (GPL)

Syntax

eval(<expression>)

<expression>. A mathematical expression, such as log(salary).

Description

Evaluates a mathematical expression for each case in the data. You can use many different mathematical functions in the expression. See the topic eval Operators and Functions (GPL) for more information. If needed, you can wrap the result of a function in another function. Therefore, datetostring(date()) is a valid expression.

The eval function is also useful for evaluating a Boolean expression whose result can be used in the summary.countTrue, summary.percentTrue, and summary.proportionTrue functions. This combination allows you to plot the number or percent of cases greater than or less than a specific value.

Examples

Figure 1. Example: Plotting the difference between two variables
TRANS: saldiff = eval(salary-salbegin)
ELEMENT: point(position(summary.mean(jobcat*saldiff)))
Figure 2. Example: Creating a graph from an equation
DATA: x = iter(-100,100,1)
TRANS: y = eval(x**2)
ELEMENT: line(position(x*y))
Figure 3. Example: Plotting percent greater than a value
TRANS: salGreaterThan = eval(salary>50000)
ELEMENT: interval(position(summary.percentTrue(jobcat*salGreaterThan)))