Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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).
like image 301
NonSleeper Avatar asked Aug 22 '16 00:08

NonSleeper


1 Answers

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.
like image 132
Jignesh Sutar Avatar answered Oct 16 '22 21:10

Jignesh Sutar