[quote="hero":21da0]:o 小弟是初学者,有如下问题请教:
<!-- s:o --><img src="{SMILIES_PATH}/icon_surprised.gif" alt=":o" title="Surprised" /><!-- s:o --> 我想实现分组累计求和,写了如下语句:
data r2;
set r1;
by tag;
if first.tag then do;
retain tturn 0;
end;
tturn+turn;
run;
但在执行时retain语句总是保留了之前的值,而并没有置初值0,
请问我该如何实现?[/quote:21da0]
It's important to know that retain statement is non-executed statement and the following code may solve your problem.
proc sort data=r1;
by tag;
run;
data r2
retain tturn;
set r1;
by tag;
if first.tag then tturn=0;
tturn+turn;
if last.tag then output;
run;