要在数据步骤代码中执行此操作,您可以执行以下操作:
data want;
set have end=end; * Var 'end' will be true when we get to the end of 'have'.;
jan_sum + jan_total; * These 'sum statements' accumulate the totals from each observation.;
feb_sum + feb_total;
output; * Output each of the original obbservations.;
if end then do; * When we reach the end of the input...;
measure = 'Total'; * ...update the value in Measure...;
jan_total = jan_sum; * ...move the accumulated totals to the original vars...;
feb_total = feb_sum;
output; * ...and output them in an additional observation.
end;
drop jan_sum feb_sum; * Get rid of the accumulator variables (this statement can go anywhere in the step).;
run;
你可以通过许多其他方式做到这一点。假设您实际上有所有月份的列,您可能会重写数据步骤代码以使用数组,或者您可能使用 PROC Summary 或 PROC SQL 来计算总计并使用更短的数据步骤将结果总计加回,等等