In SPSS, SELECT IF deletes cases (rows of data) that don't satisfy some condition(s). Like so, SELECT IF basically means *“don't delete if ...”* A minimal example is
SELECT IF(GENDER = 1).

## SPSS SELECT IF - Some Examples

Say we collected data on our employees and the resulting data file is employees.sav. Our client is only interested in female respondents so we decide to delete all male respondents and those with missing values on gender. The syntax below demonstrates how to do so by using SELECT IF.

## SPSS SELECT IF Syntax

***1. Delete all non female respondents.**

select if gender ne 0.

exe.

## Notes

- If you're not sure whether you'd like to use cases at a later stage or not, use FILTER instead of SELECT IF. Like so you can exclude cases from analysis without removing them from the data.
- Another alternative for excluding cases temporarily is combining SELECT IF with TEMPORARY.
- If you'd like to analyze two (or more) groups of cases separately, use SPLIT FILE instead of SELECT IF.
- Note that you
**can't undo**SELECT IF if you delete the “wrong” cases. This is usually no big issue if you carefully work from syntax. (In this case, just rerun your syntax up to the point where you went wrong.) - You can combine more than one condition with AND and/or OR. For example, SELECT IF V1 = 1 OR V2 = 1 deletes all cases who don't have 1 on V1
*or*V2. - You can use functions within conditions. For example, SELECT IF NMISS(ALL) = 0. deletes all cases with one or more missing values (over all variables in the data).

## This tutorial has 15 comments

## By Ruben Geert van den Berg on May 22nd, 2018

Hi Nik!

Maybe something like

`IF(ANY(N,2,3) OR MISSING(N)) ....`

will do the trick?## By Nik on May 22nd, 2018

Hi Ruben! Thank you for your answer! I was wrong tor write. Really I wanted to write that "a ~= b is true if a is not b". So, for a variable N, I need SPSS select not only all numeric values different than b but ALSO missing values.

For example, I have a variable where value 1 has 10 frequencies, value 2 has 20 frequencies, variable 3 has 30 frequencies and 100 Missing values. I need to select all cases different from 1 including ALSO 100 missing cases. If now I write ANY(N,2,3) will be selected only 50 cases (2 and 3) but I would select also missing values. How could i do it?

I hope you can help me!

Thank you!

## By Ruben Geert van den Berg on May 19th, 2018

Hi Renate, please try the syntax below. I'll first create and inspect a selector variable. Only if that's correct, then I'll delete unneeded cases.

`*Set up test data with all possible combinations, assuming there's no missings.`

data list free/v v2.

begin data

1 1 2 1 3 1 1 2 2 2 3 2 1 3 2 3 3 3

end data.

*Compute selector, all zeroes.

compute selector = 0.

execute.

*Set selector to 1 if either condition below is met.

if(any(v,1,2) & any(v2,1,2)) selector = 1.

if(v = 3 & v2 = 3) selector = 1.

execute.

*If correct, delete unneeded cases.

select if(selector = 1).

execute.

delete variables selector.

`*Note: you only need the last execute command.`

## By Ruben Geert van den Berg on May 19th, 2018

Hi Renate, I'll fix this in half an hour or so. I'm starving so I really gotta have lunch first.

## By Renate on May 19th, 2018

Got it made: SELECT IF (v_223 = 3) or (Feedb ~= '-99').

But now it is getting more complicated. Participants were randomly assigned to one of three conditions andat the end they were asked what condition they remember. There are two variables: V=1,2,3 and V2=1,2,3. Now I want all cases with V=1 or 2 and V2 =1 or 2 but not V2 = 3 and all cases V =3 and V2=3 but not V2= 1 or 2. Is that understandable? And is ther a solution for it? Thanks