Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Statscraft 0.61.0, release v0.61.0

IF

Assign a value only for the cases where a condition holds.

Syntax

IF (condition) target = expression.

The parentheses around the condition are optional. The command sets target only for the cases where the condition is true; where it is false or missing the target keeps its value. A new target starts as system-missing (numeric, F8.2) for every case, so cases the condition leaves out stay missing. A string target must exist first (STRING). Several IF commands in a row are checked one after another, so a later one may overwrite an earlier one.

Example

GET FILE='survey.sav'.
IF (satisfaction <= 2 AND switching = 1) at_risk = 1.
IF (age >= 60 AND ch_app = 0) offline = 1.
RECODE at_risk offline (SYSMIS = 0).
FREQUENCIES at_risk offline.

The example reads the sample data file survey.sav, an invented customer survey; save it in the folder you run the syntax from.

Example output

at_risk

CategoryValueLabelFrequencyPercentValid PercentCumulative Percent
valid026989.6789.6789.67
valid13110.3310.33100
total300100

statscraft help IF prints the same text in the terminal. All commands