Syntax, sum statement:
variable+expression;
Note: If the expression produces
a missing value, the sum statement ignores it. The sum statement is
one of the few SAS statements that do not begin with a keyword.
|
data clinic.stress;
infile tests;
input ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33
RecHR 35-37 TimeMin 39-40 TimeSec 42-43
Tolerance $ 45;
TotalTime=(timemin*60)+timesec;
SumSec+totaltime;
run;
SumSec
|
=
|
TotalTime
|
+
|
Previous total
|
---|---|---|---|---|
0
|
|
|
|
|
758
|
=
|
758
|
+
|
0
|
1363
|
=
|
605
|
+
|
758
|
2036
|
=
|
673
|
+
|
1363
|
2618
|
=
|
582
|
+
|
2036
|
3324
|
=
|
706
|
+
|
2618
|
Syntax, RETAIN statement
for initializing sum variables:
RETAIN variable <initial-value>;
Note: The following statements
are true about the RETAIN statement:
|
data clinic.stress;
infile tests;
input ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33
RecHR 35-37 TimeMin 39-40 TimeSec 42-43
Tolerance $ 45;
TotalTime=(timemin*60)+timesec;
retain SumSec 5400;
sumsec+totaltime;
run;
Now the value of SumSec begins at 5400 and increases
by the value of TotalTime with each observation.
SumSec
|
=
|
TotalTime
|
+
|
Previous Total
|
---|---|---|---|---|
5400
|
|
|
|
|
6158
|
=
|
758
|
+
|
5400
|
6763
|
=
|
605
|
+
|
6158
|
7436
|
=
|
673
|
+
|
6763
|
8018
|
=
|
582
|
+
|
7436
|
8724
|
=
|
706
|
+
|
8018
|