SPSS Statistics

 View Only
  • 1.  IF ANY

    Posted 4 days ago

    Why doesn't this throw an error:

     

    IF ANY (q0050_0001,q0051_0001,q0052_0001,q0053_0001,1) q5053_0001=1.

     

    vs.

     

    IF ANY (1,q0050_0001,q0051_0001,q0052_0001,q0053_0001) q5053_0001=1.

     

    ?

     

    Cheers,

     

    Bob

     

     


    A picture containing stop  Description automatically generated

    Robert W. Walker

    CEO & Founder

    23 S. Main St.·  Norwalk, CT 06854

    Tel. +1.203.255.0505

    https://usemotion.com/meet/rwwalker/meeting

     

     

     



  • 2.  RE: IF ANY

    Posted 4 days ago
    Both are legal.  Look up the ANY function.  It's kind of tricky.






  • 3.  RE: IF ANY

    Posted 4 days ago

    Thank you Jon, as always. I didn't understand what was happening to my syntax since no error was triggered. I put both instructions into ChatGPT and, at first, it told me that this instruction:

    IF ANY (1,q0050_0001,q0051_0001,q0052_0001,q0053_0001) q5053_0001=1.

    would indeed throw an error – but it did not in my command syntax. When I challenged it on this fact, it then told me the following:

     


     

    Ah, thank you for clarifying - that's a great observation, and it leads to a really subtle but important point about how SPSS interprets ANY(). SPSS is interpreting the first argument, q0050_0001, as the value to test, and the rest (q0051_0001, q0052_0001, q0053_0001, and 1) as the values to test it against. So this code says:

     

    "If the value of q0050_0001 is equal to any of the following: q0051_0001, q0052_0001, q0053_0001, or 1, then set q5053_0001 = 1."

     

    SPSS is syntactically permissive with ANY(). It allows both variable names and constants in the argument list, and it simply evaluates the function as ANY(value, list_of_comparisons), as in:

     

    "Does the value of q0050_0001 match any of [q0051_0001, q0052_0001, q0053_0001, 1]?"

     

    It's not an error, just a different logic - and that's why you didn't get the results you were hoping for.

     


     

    40 years later and I'm still learning things about basic functions!

     

    Cheers,

     

    Bob

     

     


    A picture containing stop  Description automatically generated

    Robert W. Walker

    CEO & Founder

    23 S. Main St.·  Norwalk, CT 06854

    Tel. +1.203.255.0505

    https://usemotion.com/meet/rwwalker/meeting

     

     

     






  • 4.  RE: IF ANY

    Posted 4 days ago
    We learn every day. It's almost like another constant.
    Shalom.
    Bereh
    Nigeria 






  • 5.  RE: IF ANY

    Posted 4 days ago
    although it gotvthis right, I have seen many things completely wrong both for SPSS and R code.  nonexistent commands or functions, even dialogboxes that don't exist or code that doesn't work.





  • 6.  RE: IF ANY

    Posted 4 days ago

    I've had the same experience, particularly when looking for more efficient ways to compress syntax. It often suggests what, at first, seems like a very elegant solution, to see it bomb out because it forgot a basic syntax rule, like non-contiguous variables. That's why we always check our work!

     

    Cheers,

     

    Bob

     

     


    A picture containing stop  Description automatically generated

    Robert W. Walker

    CEO & Founder

    23 S. Main St.·  Norwalk, CT 06854

    Tel. +1.203.255.0505

    https://usemotion.com/meet/rwwalker/meeting