
Adding two figures and get a different result from your expectation. Yes this is possible with SAS when missing or special missing values are included in your records. Let’s find out the difference between mathematics operators and functions which deals with computation taking the SUM function as an example.
Here is the rule: SAS functions ignore missing values in their computation. So with the SUM function, the sum of 2 and a missing value is 2, whether it is missing with the + operator: 2 + . = .
Now, I shall detail the three SUM function notation.
1. List values as individual SUM function parameters: parameters of a SAS functions are delimited with commas. To compute the sum of several values, one can list them one after another withint the SUM function brackets using commas as delimiter.
newvar = sum(2,3,.);
Most of the time, the programmer won’t compute raw figures but will refer to values through variables:
newvar = sum(x,y,z);
2. Use the OF keyword to list values without commas : to list the values to sum without comma, the OF keyword must be used.
newvar = sum (of 2 3 .) ;
newvar = sum(of test2 test3 test4);
3. Extension of the notation with the OF keyword : in the previous example variables have a name a common basis and an integer incremented by 1. By defining an interval, listing the first and lasst variable joined by an hyphen, you should be able to save you from a work which become more and more boring as the number of variables increases.
newvar = sum(of test2-test4);
This notation is not specific to the SUM function. It can be used in many occasions such as the keep or drop function, an array, etc.
Important: Please note how important it is not to forget the OF keyword. In the previous example, SAS would substract variables test4 to variable test2 if the OF keyword would be missing. The sum function would then have a single value.
Further Reading : the MIN and MAX functions and their related operators >< and <> deal the same way as the SUM function and its + operator with missing values.




