我的数据集看起来像这样。我想创建另一个变量,它代表每天的总交易量。我的代码如下所示。但似乎我的代码有问题,计算出的最大交易量N
在某种程度上是错误的。任何人都可以告诉我知道我的错误在哪里。
proc sort data = work.data;
by time;
run;
data work.data;
set work.data;
retain I;
by time;
if first.time then I = volume; else I = I + volume;
run;
proc sql;
create table work.data2
as select a.*, max(I) as N
from work.data as a
group by time
order by time;
quit;
ID Time Volume
Apple 1/1/2001 1000
BP 1/1/2001 1500
AAL 2/1/2001 1130
Apple 2/1/2001 1000
BP 2/1/2001 1500
AAL 2/1/2001 1130
Apple 3/1/2001 1000
BP 3/1/2001 1500
AAL 3/1/2001 1130
答案 0 :(得分:-1)
你应该以max(I)为条件。像:I = max(I);也可以通过一个proc sql尝试这个。
proc sql;
select * from (select time,sum(volume) as total from have group by time) having total=max(total);
quit;