Can fewer / more statements be used with IF ANY?
To do this, you need to create an auxiliary variable.
@ Jignesh Sutar's solution is one that works great. However, SPSS often uses several ways to accomplish a specific task.
Here's another solution where the command COUNT
comes in handy. It's important to note that the following solution assumes that the values of the variables are integers. If you have float values (like 1.5) you will get the wrong result.
* count occurrences where Q2 to Q10 is less then 2.
COUNT #QLT2 = Q2 TO Q10 (LOWEST THRU 1).
* select if Q1>10 and
* there is at least one occurrence where Q2 to Q10 is less then 2.
SELECT (Q1>10 AND #QLT2>0).
There is also a variant for this kind of solution that handles floats correctly. But I think this is less intuitive.
* count occurrences where Q2 to Q10 is 2 or higher.
COUNT #QGE2 = Q2 TO Q10 (2 THRU HIGHEST).
* select if Q1>10 and
* not every occurences of (the 9 variables) Q2 to Q10 is two or higher.
SELECT IF (Q1>10 AND #QGE2<9).
Note. Variables starting with #
are temporary. They are not stored in the dataset.
source to share
I don't think you can (it would be nice if you could - you can do something like this in Excel with COUNTIF
and SUMIF
IIRC).
You need to construct a new variable that checks slightly ANY
less than the condition, as shown below:
input program.
loop #j = 1 to 1000.
compute ID=#j.
vector Q(10).
loop #i = 1 to 10.
compute Q(#i) = trunc(rv.uniform(-20,20)).
end loop.
end case.
end loop.
end file.
end input program.
execute.
vector Q=Q2 to Q10.
loop #i=1 to 9 if Q(#i)<2.
compute #QLT2=1.
end loop if Q(#i)<2.
select if (Q1>10 and #QLT2=1).
exe.
source to share