Task
|
Example Code
|
---|---|
Subset data
|
if resthr<70 then delete; if tolerance='D'; |
Drop unwanted variables
|
drop timemin timesec; |
Create or modify a variable
|
TotalTime=(timemin*60)+timesec; |
Initialize and retain
a variable
|
retain SumSec 5400; |
Accumulate totals
|
sumsec+totaltime; |
Specify a variable's
length
|
length TestLength $ 6; |
Execute statements conditionally
|
if totaltime>800 then TestLength='Long'; else if 750<=totaltime<=800 then TestLength='Normal'; else if totaltime<750 then TestLength='Short'; |
Syntax, sum statement:
variable+expression;
Note: If the expression produces
a missing value, the sum statement ignores it.
|
data work.stresstest;
set cert.tests;
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 work.stresstest;
set cert.tests;
TotalTime=(timemin*60)+timesec;
retain SumSec 5400;
sumsec+totaltime;
run;
proc print data=work.stresstest;
run;
SumSec
|
=
|
TotalTime
|
+
|
Previous Total
|
---|---|---|---|---|
5400
|
|
|
|
|
6158
|
=
|
758
|
+
|
5400
|
6763
|
=
|
605
|
+
|
6158
|
7436
|
=
|
673
|
+
|
6763
|
8018
|
=
|
582
|
+
|
7436
|
8724
|
=
|
706
|
+
|
8018
|