SPSS Statistics

 View Only
  • 1.  COMPUTE Syntax Containing Two "Equals" Signs

    Posted Tue April 13, 2021 11:46 AM

    Hi.  Long time SPSS Statistics user with a bit of a strange question.

    Recently, I ran across a web page that contained an example showing a "COMPUTE" statement that contained two equals signs.   It was something like "COMPUTE x = y = z".  This was new to me however, I was in a rush so didn't mentally land on it.  Coming back to it now and I can't seem to find any reference to the hows/whys of this application in any of my SPSS documentation nor on the web.

    Can somebody point me to information on what this COMPUTE format means?

    Thanks in advance.



    ------------------------------
    Scott Terry
    ------------------------------

    #SPSSStatistics


  • 2.  RE: COMPUTE Syntax Containing Two "Equals" Signs

    IBM Champion
    Posted Tue April 13, 2021 11:54 AM
    The equals sign has two different roles: assignment and test for equality.  In your example, it is testing equality of y and z and assigning the result to x.  It would be clearer if written as
    compute x = y eq z.
    The result will be 0 or 1 depending on the outcome of the test.

    --





  • 3.  RE: COMPUTE Syntax Containing Two "Equals" Signs

    Posted Mon April 19, 2021 09:01 AM
    Thanks Jon and Rick.  This will be very helpful.

    Regards!

    ------------------------------
    Scott Terry
    ------------------------------



  • 4.  RE: COMPUTE Syntax Containing Two "Equals" Signs

    Posted Tue April 13, 2021 12:00 PM
    It's a boolean evaluation; returns 0 if false and 1 if true. Here 1 if y = z, else 0 (or sysmis if args missing).

    data list free /y z.
    begin data.
    1 2
    1 1
    end data.
    compute x = y = z.
    list.
    ​

    I'll look in the Command Syntax Reference in a couple of places and see if that's mentioned.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 5.  RE: COMPUTE Syntax Containing Two "Equals" Signs

    Posted Mon April 19, 2021 09:03 AM
    Thanks Rick.  Very clear.

    ------------------------------
    Scott Terry
    ------------------------------



  • 6.  RE: COMPUTE Syntax Containing Two "Equals" Signs

    Posted Mon April 19, 2021 09:43 AM
    You're welcome. Just FYI - The help refers to these as "logical expressions." Cf Logical Expressions


    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 7.  RE: COMPUTE Syntax Containing Two "Equals" Signs

    Posted Mon April 19, 2021 11:37 AM
    Fantastic.  Thanks again!

    ------------------------------
    Scott Terry
    ------------------------------