SAS中文论坛

标题: 求助!关于retain语句! [打印本页]

作者: shiyiming    时间: 2004-3-12 15:22
标题: 求助!关于retain语句!
<!-- s:o --><img src="{SMILIES_PATH}/icon_surprised.gif" alt=":o" title="Surprised" /><!-- s: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,

请问我该如何实现?
作者: shiyiming    时间: 2004-3-12 20:25
标题: Re: 求助!关于retain语句!
[quote=&quot;hero&quot;: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;
作者: shiyiming    时间: 2004-3-12 22:46
Please be noted that you should add a BY TAG after PROC SORT.
作者: shiyiming    时间: 2004-3-13 11:14
标题: 谢谢!
谢谢楼上的两位大哥! <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->  <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2