Hi:
Well, without a BY statement, your logic will never work correctly. But if you ONLY want the final value (or grand total of TIM) to show, then why not use one of the SAS reporting procedures instead of using a DATA step program. There's no need to add everything up yourself if all you want is a grand total or even a breakdown by CASENUMBER and CODE.
However, my tendency would be to use either PROC MEANS, PROC REPORT or PROC TABULATE to get the total of the TIM variable. By default, missing values are ignored in the calculation of statistics, so the test for NOT MISSING is already taken care of when you use SAS procedures to generate statistics, such as summing.
In the code below, I'm showing the PROC REPORT and PROC TABULATE and PROC MEANS methods. All 3 procedures will create and output dataset. PROC MEANS uses the OUTPUT statement, while PROC REPORT and PROC TABULATE both use the the OUT= option on the PROC statement. The reason I prefer PROC REPORT and PROC TABULATE over PROC MEANS is that I can get subtotals and grand totals in the same report with either REPORT and TABULATE and with PROC MEANS, a bit more processing would be required to get the CASENUMBER or CASENUMBER/CODE breakdown along with the GRAND TOTAL.
There is a lot of good documentation on all 3 of these procedures. I hope that the examples below will get you started.
cynthia
[pre]
** Uses CASES data, as shown in my previous posting;
ods listing;
proc report data=cases nowd;
title '1a) PROC REPORT get grand total only';
column tim;
define tim / sum "Time";
run;
proc report data=cases nowd;
title '1b) PROC REPORT get case breakdown';
column casenumber tim;
define casenumber / group "Case";
define tim / sum "Time";
rbreak after / summarize;
run;
proc report data=cases nowd;
title '1c) PROC REPORT get case and code';
column casenumber code tim;
define casenumber / group "Case";
define code / group "Code";
define tim / sum "Time";
rbreak after / summarize;
run;
proc report data=cases nowd;
title '1d) PROC REPORT get code breakdown only';
column code tim;
define code / group "Code";
define tim / sum "Time";
rbreak after / summarize;
run;
proc tabulate data=cases;
title '2a) PROC TABULATE get grand total only';
var tim;
table tim*sum;
label tim="Time";
run;
proc tabulate data=cases;
title '2b) PROC TABULATE get casenumber breakdown';
class casenumber;
var tim;
table casenumber all,
tim*sum;
label tim="Time"
casenumber="Case";
run;
proc tabulate data=cases;
title '2c) PROC TABULATE get casenumber and code breakdown';
class casenumber code;
var tim;
table casenumber*code all,
tim*sum;
label tim="Time"
casenumber="Case"
code="Code";
run;
proc tabulate data=cases;
title '2d) PROC TABULATE get code breakdown only';
class code;
var tim;
table code all,
tim*sum;
label tim="Time"
code="Code";
run;
proc means data=cases sum;
title '3a) Grand Total of TIM only';
var tim;
run;
proc means data=cases sum;
title '3b) PROC MEANS get casenumber breakdown';
class casenumber;
var tim;
run;
proc means data=cases sum;
title '3c) PROC MEANS get casenumber and code breakdown';
class casenumber code;
var tim;
run;
proc means data=cases sum;
title '3d) PROC MEANS get code breakdown';
class code;
var tim;
run;
[/pre]