Arithmetic definitions

<< Click to Display Table of Contents >>

Navigation:  Reference Manual > Definitions >

Arithmetic definitions

Arithmetic definitions are only used for variables of type Integer and Float (Weight).

An arithmetic definition comprises one or more values (entries or constants) combined with arithmetic operators + - * / (add, minus, multiply, divide).

You can refer to integer, float and single-coded entries in any arithmetic definition.  You can also refer to $serial which refers to the serial number as an integer.

When single-coded entries are used in arithmetic, the value used is the response number selected, or 0 (zero) if no responses are selected unless there is a supplemental reject response in which case the response number of the reject response will be used.

IMPORTANT: Be careful not to use supplemental rejects on entries used in arithmetic; copy to a variable and add the reject to the variable.

IMPORTANT: when typing syntax, entry names must be preceded by a dollar sign ($).

Arithmetic definitions are always calculated using floating point values.  If the result is to be stored in an integer variable then the calculated answer is rounded to the nearest whole number, if necessary.

There is an option for a variable to treat U (undefined) values as zero.  U is a special value given to value questions that were filtered (not asked) or left empty.

IMPORTANT:  unless the option to treat U as 0 is set, then any U (undefined) value referred to in the definition will cause the result to be U (undefined).

For practical reasons the program allows zero divided by zero as giving the value zero.  Any other value divided by zero will give the value U unless the option to treat U as 0 is set.

If more than one arithmetic operator is used without parentheses, the expression will be evaluated left to right. So:

$Q5 + $Q6 * 100 means ($Q5 + $Q6) * 100

Using parentheses we can only multiply Q6 by 100:

$Q5 + ($Q6 * 100)

Functions

There are some functions that can be used as an arithmetic definition:

CT($entry)

The entry must be an earlier multi-coded entry and the calculated value is a count of the number of selected responses.

SCORE($entry)

The entry must be single-coded or multi-coded with score values assigned to the responses.

The calculated value is the score assigned to the first selected response with a score assigned.  If no selected responses have a score assigned then the calculated value is undefined (U).

Summary rows (for example top 2 or bottom 2) in multi-coded entries should not have a score value assigned to them.

MIN($entry1,$entry2, ... )

The entries must have a value (single-coded, integer, float, date, time).  The value is the smallest value found in any of the listed entries.  Up to 100 entries can be listed.

Any entries that are undefined will be ignored.  If all the entries are undefined then the result stored will be undefined. The "treat undefined as zero" setting has no effect on min() function.

MAX($entry1,$entry2, ... )

The entries must have a value (single-coded, integer, float, date, time).  The value is the largest value found in any of the listed entries.  Up to 100 entries can be listed.

Any entries that are undefined will be ignored.  If all the entries are undefined then the result stored will be undefined. The "treat undefined as zero" setting has no effect on max() function.