Sum operator

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6209 Score: 0
    Andee Rubin
    Participant
    4 pts

    I tried to add up a bunch of variables across a row using the SUM() operator and got strange results.  I listed the variables to be added inside the SUM parentheses separated by commas.  Is that not the right format?  If I use standard infix notation (V1+ V2 + V3), I get the expected results.  I can provide the file if it’s obvious to you what’s going on.

    #6210
    Andee Rubin
    Participant
    4 pts

    Sorry – I mean I can supply the file if it’s NOT immediately obvious to you what’s going on!

    #6211
    Bill Finzer
    Keymaster

    Hi Andee,

    The sum function expects a single expression to be summed over all cases. Here’s the documentation:

    sum(number, filter) Returns the sum of its argument evaluated for every case.

    sum(grade_point) computes the sum of the grade points

    sum(Mass, Height>60) returns the sum of the masses for heights taller than 60

    The strange results you get from sum(V1,V2,V3) are the result of summing the values of V1 over all cases for which V2 look true, totally ignoring V3.

    V1+V2+V3 is the best way to get the sum of the values for the three attributes for each case.

    Hope this helps,

    Bill

    #6212
    Andee Rubin
    Participant
    4 pts

    Totally helps!  I will not use that function again for these purposes!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.