【发布时间】:2015-09-03 14:44:13
【问题描述】:
我有一个如下所示的数据集:
company Assets Liabilities strategy1 strategy2 strategy3.....strategy22
1 500 500 0 50 50 50
2 200 300 33 30 33 0
我的目标是找到所有策略(策略 1 - 策略 22)的最大值,并且基本上按照他们使用的策略来划分公司。当一些公司在多种策略下具有相同的最大值时,就会出现问题。在这种情况下,我想将公司放入多个桶中。最终的数据集将是这样的:
company Assets Liab. strategy1 strategy2 strategy3.....strategy22 Strategy
1 500 500 0 50 50 50 Strategy2
1 500 500 0 50 50 50 Strategy3
1 500 500 0 50 50 50 Strategy22
等等。 最终目标是能够通过策略对公司的资产、负债等进行处理。到目前为止,我已经能够获得接近我想要的数据集,但是在“策略”列中我无法获得它,因此 SAS 并不总是输出具有最大值的第一个策略。
Data want;
set have;
MAX = max(of strategy1-strategy22);
array nums {22} strategy1-strategy22;
do _n_=1 to 21;
count=1;
do _i_ = _n_+1 to 22;
if nums{_n_} = nums{_i_} AND nums{_i_} ne 0 then count + 1;
end;
if count > maxcount then do;
mode = nums{_n_};
maxcount = count;
end;
end;
Run;
Data want2;
set want (where=( maxcount > 1 AND Mode = Max));
by company;
strat=1;
do until (strat gt maxcount);
output;
strat = strat +1;
end;
Run;
基本上,我计算了相同最大值的众数和计数,如果 maxcount > 1 且众数 = max,则我输出相同的观测值。但是,如果有多个相同的最大值,我对如何让 SAS 输出不同的策略感到困惑。
【问题讨论】:
-
我不熟悉 SAS,但我会循环遍历公司的每个策略以找到最高分(例如,50),然后遍历每个策略并添加如果该策略的得分等于之前计算的最大得分,则将其放入策略的存储桶中。正如我所说,我不是很了解你的代码,但看起来你已经实现了前半部分。
标签: sas