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

COMPUTE

Assign the value of an expression to a variable.

Syntax

COMPUTE target = expression.

The command sets target to the value of the expression for every case. A new target is numeric with format F8.2; an existing one keeps its format and labels. A string target must exist first (STRING), and a longer text is cut to its width.

When a value the expression needs is missing (system-missing, or a user-missing value of the variable), the result is system-missing, except in functions that skip missing values, such as MEAN, SUM and NVALID, and in MISSING, SYSMIS and VALUE. Operators and functions are listed under the general rules on the command index and in statscraft help.

COMPUTE is a transformation: it runs when the next procedure or EXECUTE reads the data.

Example

GET FILE='survey.sav'.
COMPUTE spend_year = spend * 12.
COMPUTE channels = SUM(ch_web, ch_app, ch_phone, ch_store, ch_email).
COMPUTE days_in = DATEDIFF(interview_date, DATE.DMY(5, 10, 2026), 'days').
DESCRIPTIVES spend_year channels days_in.

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

Descriptive Statistics

VariableLabelNMeanStd DevMinimumMaximum
spend_year284462.11158.57163.561134.24
channels3002.081.0205
days_in30020.9812.82041
Valid N (listwise)284
Missing N (listwise)16

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