DATA Step, Macro, Functions and more

difference between sum() and +<operator>

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

difference between sum() and +<operator>

 

data work.passengers;
TransPassengers = 100;
OrigPassengers = .;
Totalusingoperator = OrigPassengers + TransPassengers;
Totalusingfunction = Sum(OrigPassengers,TransPassengers);
put Totalusingoperator;
put Totalusingfunction;
run;

Please explain the logic of output why value of Totalusingoperator is . and Totalusingfunction is 100.

 

Thanks in Advance,

Ayushmaan

 


Accepted Solutions
Solution
‎09-02-2017 11:06 AM
PROC Star
Posts: 768

Re: difference between sum() and +<operator>

[ Edited ]

As you can see in the documentation for the SUM function here,  the SUM function "Returns the sum of the nonmissing arguments.", i.e. the sum function ignores the missing value. On the other hand, when you use a missing value with an arithmetic operator (+, - etc), it returnsa missing value.

View solution in original post


All Replies
Solution
‎09-02-2017 11:06 AM
PROC Star
Posts: 768

Re: difference between sum() and +<operator>

[ Edited ]

As you can see in the documentation for the SUM function here,  the SUM function "Returns the sum of the nonmissing arguments.", i.e. the sum function ignores the missing value. On the other hand, when you use a missing value with an arithmetic operator (+, - etc), it returnsa missing value.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 229 views
  • 2 likes
  • 2 in conversation