公卫百科  > 所属分类  >  SAS   
[0] 评论[0] 编辑

SAS Retain Statement

The retain statement is used to hold the values of variables accross iterations of the data step. Normally, all variables in the data step are set to missing at the start of each iteration of the data step.

The usage retain x y; retains the values of the variables x and y accross data step iterations. The usage retain; will retain the values of all variables used in the data step accross iterations of the data step.
公卫百科


As a simple example, look at the following program attempting to compute values of y(n)=2*y(n-1) with y(1)=1.


data dumb;
if _n_=1 then y=1;
else y=2*y1;
y1=y;
if _n_ =100 then stop;
run;


Since values are set to missing at the start of a data step iteration, the data set dumb will contain one value 1 and the other 99 values of y will be missing. 公卫百科

The following program produces the desired data set.


data smart;
retain y1;
if _n_=1 then y=1;
else y=2*y1;
y1=y;
if _n_ =100 then stop;
run;

附件列表


0

词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。

如果您认为本词条还有待完善,请 编辑

上一篇 SAS Return Statement    下一篇 SAS Pagesize Option

标签

暂无标签

同义词

暂无同义词