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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With