Question & Answer
Question
How do I select cases in SPSS for Windows using either syntax or the windows?
Answer
Go to Data->Select cases and select 'If condition is satisfied'. Enter a conditional statement, click Continue, and then, OK. If the condition contains a variable that is string, make sure you type single quote marks around each end of the string. The pasted syntax appears below, along with a sample data file.
DATA LIST / v1 1 (f) v2 2 (a).
BEGIN DATA
1a
1a
1b
2b
2c
2c
3d
3d
END DATA.
EXE.
*Pasted syntax for selecting on numeric variable.
USE ALL.
COMPUTE filter_$=(v1=1).
VARIABLE LABEL filter_$ 'v1=1 (FILTER)'.
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMAT filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE .
*Pasted syntax for selecting on string variable.
USE ALL.
COMPUTE filter_$=(v2='b').
VARIABLE LABEL filter_$ "v2='b' (FILTER)".
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMAT filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE.
Alternatively, using a SELECT command from syntax will delete unselected cases from the file.
SELECT IF (V1=1).
EXE.
The addition of a TEMPORARY command will limit the selection to the following proceedure, after which the selection becomes inactive.
TEMPORARY.
SELECT IF (v1=1).
FREQ VARS=V2.
EXE
Related Information
Historical Number
20712
Was this topic helpful?
Document Information
Modified date:
16 April 2020
UID
swg21475402