Question

Is it possible to use Nested if any command in spss? for example

 if any(1, a to c) and if (1, s to x) xx=1.
Was it helpful?

Solution

Sure, but your syntax isn't quite right. if (any(1, a to c) and any(1, s to x)) xx=1.

The if expression can be arbitrarily complicated, but it needs to be an expression. The if part is a statement.

HTH

OTHER TIPS

Just to provide an answer that clarifies the nested part, here's an example using do if instead of if.

do if any(1, a to c).
    do if any(1, s to x).
        compute xx=1.
    end if.
end if.

This code finds rows with at least one time a score of 1 on any of the variables a to c. Only among these rows, it finds rows with at least one time a score of 1 on any of the variables s to x. The rows that pass the first statement and subsequently pass the second statement are assigned xx=1.

It yields the same results as:

if any(1, a to c)andany(1, s to x) xx=1.

However, the following yields different results:

if any(1, a to c) xx=1.
if any(1, s to x) xx=1.

This essentially means the same as using or between 2 conditional statements

if any(1, a to x)orany(1, s to x) xx=1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top