What are the differences between the sum function and using "+" operator? | Eklavya Online

What are the differences between the sum function and using “+” operator?

The SUM function returns the sum of non-missing arguments whereas “+” operator returns a missing value if any of the arguments are missing. Consider the following example.

Example:

  1. data exampledata1;
  2. input a b c;
  3. cards;
  4. 44 4 4
  5. 34 3 4
  6. 34 3 4
  7. . 1 2
  8. 24 . 4
  9. 44 4 .
  10. 25 3 1
  11. ;
  12. run;
  13. data exampledata2;
  14. set exampledata1;
  15. x = sum(a,b,c);
  16. y=a+b+c;
  17. run;
    In the output, the value of y is missing for 4th, 5th, and 6th observation as we have used the “+” operator to calculate the value of y.

x y
52 52
41 41
41 41
3 .
28 .
48 .
29 29