SPSS Scratch Variables
SPSS tutorials website header logo SPSS TUTORIALS VIDEO COURSE BASICS ANOVA REGRESSION FACTOR

SPSS Scratch Variables

Definition

Scratch variables are temporary helper variables that don't show up in your data. A variable is a scratch variable if (and only if) its name starts with "#".

SPSS Scratch Variable - Introduction

SPSS Syntax Example

*1. Create data.

data list free / phone(a11).
begin data
020-2868825 020-8243613 075-6485421 010-9854183 0249-897201
010-0039658 0249-985638 023-5925133 020-0520029 075-3297331
end data.

*2. Determine position of "-" sign.

compute position = char.index(phone,'-').
exe.

*3. Extract area code by using substring.

string area (a4).
compute area = char.substr(phone,1,position - 1).
exe.

SPSS Scratch Variable - Example

SPSS Scratch Variable - Syntax Example

*1. Delete new variables prior to alternative approach.

delete variables position area.

*2. Determine position of "@" sign.

compute #position = char.index(phone,'-').

*3. Extract area code by using substring.

string area (a4).
compute area = char.substr(phone,1,#position - 1).
exe.

SPSS Scratch Variable - Special Features

SPSS Scratch Variable - Syntax Examples

*1. Create mini test dataset.

data list free/id.
begin data
1 2 3 4 5
end data.

*2. The calculation of #sum starts off from the previous value. Therefore, a cumulative sum is calculated like so.

compute #cumulative = sum(id,#cumulative).
compute cumulative = #cumulative.
exe.

*3. Delete 'cumulative' prior to next example.

delete variables cumulative.

*4. The first 'exe' triggers a data pass which deletes #cumulative. This causes the second 'compute' to fail.

compute #cumulative = sum(id,#cumulative).
exe.

compute cumulative = #cumulative.
exe.

Tell us what you think!

*Required field. Your comment will show up after approval from a moderator.

THIS TUTORIAL HAS 1 COMMENT: