如何更改我的SAS代码以查找最大数量

时间:2015-06-17 16:44:01

标签: sas

我的数据集看起来像这样。我想创建另一个变量,它代表每天的总交易量。我的代码如下所示。但似乎我的代码有问题,计算出的最大交易量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

1 个答案:

答案 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;