作业帮 > 综合 > 作业

SAS retain 语句

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/17 04:22:54
SAS retain 语句
data sample;
input ID $ type income;
cards;
1 1 200
1 2 300
1 3 100
2 1 200
2 3 100
2 4 100
;
run;
data new_sample;
set sample;
by id;
retain new_income;
if first.id then new_income=0;
new_income+income;
if last.id then output;
drop income type;
run;
data new_sample2;
set sample;
by id;
if first.id then new_income=0;
new_income+income;
if last.id then output;
drop income type;
run;
为什么这两个程序结果一样?体现不出来retain的作用啊?
累加语句new_income+income;相当于下面的程序段:
retain new_income 0;
new_income=sum(new_income,income);
所以说,上面的两个程序都使用了retain的功能,结果当然一样!
想体现出retain的作用,可以试试把累加语句new_income+income;改为
new_income=sum(new_income,income);