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:
- data exampledata1;
- input a b c;
- cards;
- 44 4 4
- 34 3 4
- 34 3 4
- . 1 2
- 24 . 4
- 44 4 .
- 25 3 1
- ;
- run;
- data exampledata2;
- set exampledata1;
- x = sum(a,b,c);
- y=a+b+c;
- 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