标题: 需增加一列数据,急等解答 [打印本页] 作者: shiyiming 时间: 2010-1-28 16:10 标题: 需增加一列数据,急等解答 现有数据集A,其中有3个变量x、y、z
x y z
1 2 3
2 3 4
1 3 2
现在要增加一个变量t,t的数据是z变量所有数据的和,即
x y z t
1 2 3 9
2 3 4 9
1 3 2 9
应该如何编程?刚用SAS,求教各位大侠作者: shiyiming 时间: 2010-1-28 16:29 标题: Re: 需增加一列数据,急等解答 [code:3l4uxqon]data raw;
input x y z;
datalines;
1 2 3
2 3 4
1 3 2
;
data temp;
retain x y z total_z;
if _n_=1 then
do until(eof);
set raw(keep=z) end=eof;
total_z+z;
end;
set raw;
run;[/code:3l4uxqon]作者: shiyiming 时间: 2010-1-29 08:46 标题: Re: 需增加一列数据,急等解答 用SQL也可以的,呵呵,另一种解法。
[code:2kmy7j1v]data raw;
input x y z;
datalines;
1 2 3
2 3 4
1 3 2
;
proc sql;
create table tmp as
select *,sum(z) as t
from raw;
quit;
[/code:2kmy7j1v]