SAS:在数据步骤中实时计算标准偏差

SAS:在数据步骤中实时计算标准偏差,sas,Sas,我有以下样本数据: data have; input username $ stake betdate : datetime.; dateOnly = datepart(betdate) ; format betdate DATETIME.; format dateOnly ddmmyy8.; datalines; player1 90 12NOV2008:12:04:01 player1 -100 04NOV2008:09:03:44 player2 120 07NOV2008:14:03

我有以下样本数据:

data have;
 input username $ stake betdate : datetime.;
dateOnly = datepart(betdate) ;
format betdate DATETIME.;
format dateOnly ddmmyy8.;
datalines; 
player1 90 12NOV2008:12:04:01
player1 -100 04NOV2008:09:03:44
player2 120 07NOV2008:14:03:33
player1 -50 05NOV2008:09:00:00
player1 -30 05NOV2008:09:05:00
player1 20 05NOV2008:09:00:05
player2 10 09NOV2008:10:05:10
player2 -35 15NOV2008:15:05:33
run;
PROC PRINT; RUN;
proc sort data=have;
by username betdate;
   run;
 data want;
set have;
by username dateOnly betdate;   
retain calendarTime eventTime cumulativeDailyProfit standardDeviationStake;
if first.username then calendarTime = 0;
if first.dateOnly then calendarTime + 1;
if first.username then eventTime = 0;
if first.betdate then eventTime + 1;
if first.username then cumulativeDailyProfit = 0;
if first.dateOnly then cumulativeDailyProfit = 0;
if first.betdate then cumulativeDailyProfit + stake;
run;
PROC PRINT; RUN;
我需要一些方法来比较不同赌注大小的玩家,并使他们的赌注正常化。对于每个玩家的下注,我考虑计算出该下注的标准偏差(如下所示)。然后我可以加上这些的平方,得到平方根,得到每个玩家下注的总标准偏差。然后我可以将玩家玩的每一个赌注与他的总标准差进行比较

如果这场比赛是掷硬币,获胜的概率是0.50。这是一个二项式结果,因此标准偏差为σ=(p(1− p) /n)1/2。因此,上述第一次下注的标准偏差为90*[0.5*0.5]^0.5=45

我如何计算每个玩家的标准差,就像我计算了下面的累积利润值一样?我可能需要每个下注的标准偏差(每个玩家),每个玩家的总标准偏差,以及“标准化赌注”,即下注的赌注除以下注的标准偏差。然后我可以对不同赌注大小的玩家进行比较

我非常感谢在这方面的任何帮助


谢谢。

标准偏差对一次下注没有任何意义;它只对一名球员的总体或某一特定时间段内的球员有意义。选择特定定义(即,什么时间段等)远远超出堆栈溢出的范围;这将是一个交叉验证的问题。但是,计算标准偏差本身肯定在范围之内:

proc means data=have;
class username;
var stake;
output out=want stddev=stake_stddev;
run;
您可以添加
类型用户名语句,如果您不希望跨所有玩家stddev。你也可以要求一个平均值或总和或任何你觉得有用的东西

如果要跨时间段执行此操作,可以创建一个具有时间段变量的数据集,根据需要重复行,使它们处于符合条件的每个时间段,然后将其添加到class语句中;或者,您可以使用其中一个ETS程序(ETS=时间序列分析)
PROC EXPAND
可能是您的最佳选择,因为它为您提供了将变量转换为其STDEV sum和/或USS/CSS(以及许多其他选项)的选项。如果您已获得该许可,并且发现它很有用,请在注释中这样说,我或其他人可以帮助构建该代码