Not applicable
Posts: 0

# sum

a=3+.;
b=.+.;
c=sum(3,.);
d=sum(.,.);
what will the result? how it comes? please explain
SAS Super FREQ
Posts: 9,371

## Re: sum

Hi:
To find the results, you need to put the statements in a DATA step program. The program code and results are shown below from the SAS log:
[pre]
1077 data testsum;
1078 a=3+.;
1079 b=.+.;
1080 c=sum(3,.);
1081 d=sum(.,.);
1082 put _all_;
1083 run;

NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line)Column).
1078:4 1079:4
a=. b=. c=3 d=. _ERROR_=0 _N_=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line)Column).
1 at 1081:3
NOTE: The data set WORK.TESTSUM has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.07 seconds
cpu time 0.00 seconds

[/pre]

The SUM function returns the sum of non-missing values, as clearly explained in the documentation:
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245953.htm

The documentation on assignment statements also explains how missing values are treated when you work with arithmetic operators in an assignment statement:
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001334675.htm
In particular, look for the section entitled "Propagation of MIssing Values", where it states that:
"When you use a missing value in an arithmetic expression, SAS sets the result of the expression to missing. If you use that result in another expression, the next result is also missing. In SAS, this method of treating missing values is called propagation of missing values."

cynthia
Discussion stats