我想问一个关于累积金额的问题。我想通过使用简单的样本我可以更好地解释。所以,我有以下数据集:
Class-Path: folder/
我想获得以下数据集:
Group Time Value
A 14:25 5
A 14:25 10
A 14:26 8
B 14:25 4
B 14:25 7
C 14:25 12
C 14:25 3
C 14:26 6
C 14:26 9
答案 0 :(得分:1)
准备数据:
data a;
time ="14:25";
group="A";
value=5;
output;
time ="14:25";
group="A";
value=10;
output;
time ="14:26";
group="A";
value=8;
output;
time ="14:25";
group="B";
value=4;
output;
time ="14:25";
group="B";
value=7;
output;
time ="14:25";
group="C";
value=12;
output;
time ="14:25";
group="C";
value=3;
output;
time ="14:26";
group="C";
value=6;
output;
time ="14:26";
group="C";
value=9;
output;
run;
转置数据:
options missing=0;
proc sql noprint;
CREATE TABLE a2 AS
SELECT time
,group
,sum(value) as value
FROM a
GROUP BY time,group
;
quit;
proc transpose data=a2;
by time;
id group;
var value;
run;
您也可以使用proc sql
:
proc summary
proc summary data=a sum nonobs noprint nway;
class time group;
var value;
output out=a2(drop=_type_ _freq_) SUM()=;
run;