<< SPSS Syntax >>
(PSY206) Data Management and Analysis
Basic Rules of SPSS Syntax
SPSS syntax is structured and rule-based. Understanding these fundamentals makes data handling faster, cleaner, and more reliable.
1. Every command must end with a period (.)
SPSS does not run a command until it sees a period.
FREQUENCIES VARIABLES = age.
DESCRIPTIVES VARIABLES = score.2. SPSS is NOT case-sensitive (for commands & variable names)
These all mean the same thing:
age AGE Age
descriptives DESCRIPTIVES Descriptives
However, string values ARE case-sensitive:
SELECT IF gender = "male".4. Spaces and line breaks do NOT matter
SPSS ignores extra whitespace.
DESCRIPTIVES VARIABLES = age income.is identical to:
DESCRIPTIVES
VARIABLES = age income
.5. / begins a subcommand
The slash starts the next section of the command.
FREQUENCIES VARIABLES = q1 q2 q3
/STATISTICS = MEAN MEDIAN STDDEV
/HISTOGRAM.In DATA LIST LIST /, the / means: “Now start defining variables.”
6. Basic transformation commands
COMPUTE total = q1 + q2 + q3.
IF (gender = 2) female = 1.
RECODE adopted (0=0) (1,2,3=1) INTO adopt_bin.
COUNT agree1 = q1 TO q10 (1).These modify or create variables.
7. Sorting, filtering, and splitting
SORT CASES BY age (A).COMPUTE filter_$ = (adopted > 0).
FILTER BY filter_$.SPLIT FILE BY gender.Turn off when done:
FILTER OFF.
SPLIT FILE OFF.8. Reading data
Manual entry:
DATA LIST LIST /
id (F2.0)
score (F2.0).
BEGIN DATA
1 20
2 18
END DATA.Excel import:
GET DATA
/TYPE=XLSX
/FILE="mydata.xlsx"
/READNAMES=ON.9. The role of EXECUTE.
EXECUTE. is a special command that forces SPSS to apply all pending data transformations immediately.
Many transformation commands—such as COMPUTE, IF, RECODE, COUNT, VALUE LABELS, FORMATS—do not run instantly. They wait until:
- SPSS reaches an analysis command, or
- You manually force the update using
EXECUTE.
Example:
COMPUTE score2 = score * 2.
EXECUTE.Without EXECUTE., the new variable may not appear in the Data Editor until the next analysis (e.g., FREQUENCIES).
When EXECUTE. is useful:
- When you only run transformations and no analysis follows
- When you want to immediately see changes in Data View
- When debugging or teaching step-by-step
- When building variables interactively
When you do NOT need EXECUTE.:
- When a procedure (FREQUENCIES, DESCRIPTIVES, T-TEST, REGRESSION, etc.) follows the transformation → These automatically trigger execution.
When to avoid overusing it:
- Repeated
EXECUTE.commands in large datasets slow down processing → Combine several transformations and run oneEXECUTE.at the end.
10. Commands run from top to bottom
Order matters. Create variables before using them:
COMPUTE total = q1 + q2 + q3.
DESCRIPTIVES VARIABLES = total.11. Good habits for clean SPSS syntax
- Keep each command on its own line
- Indent subcommands (lines starting with
/) - Use meaningful variable names
- Use
RECODE INTOto avoid overwriting raw data - Add comments to explain logic
- Group transformations together and end with one
EXECUTE.
3. Comments begin with
/*and must end with a*/