NonSleeper
NonSleeper

Reputation: 851

How to select cases based on criteria of several variables in SPSS?

In a dataset, there are 10 variables V1, V2,..., V10.

How can I select cases in which the value of any of those variables is greater or equal, say, 10?

I tried this but it didn't work:

temporary.
select if any(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, ge 10).
list id.

This and a couple of others didn't work either:

select if ((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) ge 10).

Upvotes: 5

Views: 6036

Answers (3)

horace_vr
horace_vr

Reputation: 3166

This will also work:

count cnt_ = v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 (10 thru highest).
exe.
select if cnt_>0.
exe.

The cnt_variable is used for counting how many variables have a value of 10 or greater. Then the selection command selects what you need.

Also, don't forget about execute, to apply all pending transformations. Otherwise nothing will happen.

Upvotes: 1

Jignesh Sutar
Jignesh Sutar

Reputation: 2929

You could use VECTOR/LOOP approach here and specifying the loop to be exited as soon as the first variable meets the given criteria, in your case variable to be greater than value of 10, so to not unnecessarily continue looping over remaining variables:

*****************************************.
* set up dummy data.
set seed = 10.
input program.
loop #i = 1 to 500.
compute case = #i.
end case.
end loop.
end file.
end input program.
dataset name sim.
execute.
vector v(10, F1.0).
do repeat v = v1 to v10.
compute v = TRUNC(RV.UNIFORM(1,12)).
end repeat.
execute.
*****************************************.

vector v=v1 to v10.
loop i=1 to 10.
  if (v(i) > 10) Keep=1.
end loop if v(i) > 10.
select if Keep.

Upvotes: 4

eli-k
eli-k

Reputation: 11310

You'll have to loop for it:

do repeat vr=v1 to v10.
   if vr ge 10 KeepMe=1.
end repeat.
select if KeepMe=1.

Upvotes: 3

Related Questions