SAS: Calculate Standard Deviation on-the-fly in datastep -


i have following sample data:

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; username betdate;    run;  data want; set have; username dateonly betdate;    retain calendartime eventtime cumulativedailyprofit standarddeviationstake; if first.username calendartime = 0; if first.dateonly calendartime + 1; if first.username eventtime = 0; if first.betdate eventtime + 1; if first.username cumulativedailyprofit = 0; if first.dateonly cumulativedailyprofit = 0; if first.betdate cumulativedailyprofit + stake; run; proc print; run; 

i need way of comparing players different stake sizes , normalize betting stakes. each player's bet, thinking of calculating standard deviation out bet (as below). add squares of these , square root have total standard deviation of each players bets. compare each stake being playing player total standard deviation.

if game coin toss, probability of winning 0.50. binomial outcome, standard deviation σ = (p(1 − p)/n)1/2. standard deviation of first bet above 90*[0.5*0.5]^0.5 = 45.

how can calculate standard deviation of each players stake calculated cumulative profit values below? need standard deviation of each bet (for each player), total standard deviation each player, , 'normalised stake' i.e. stake of bet divided standrad deviation of bet. can kind of comparision between players different magnitudes of stake.

i'd appreciate @ on this!

thanks.

standard deviation not have meaning single bet; have meaning either player in total, or player on particular period of time. choice of particular definition (ie, time period, etc.) out of scope stack overflow; crossvalidated question. however, calculating standard deviation in scope:

proc means data=have; class username; var stake; output out=want stddev=stake_stddev; run; 

you can add type username; statement if don't want across-all-players stddev. can ask mean or sum or whatever find useful.

if want across time periods, either can create dataset has time period variable, repeats rows needed they're in every time period qualify for, , add class statement; or can use 1 of ets procs if have licensed (ets = time series analysis). proc expand best bet gives option of transforming variable stdev sum and/or uss/css (among many other options). if have licensed , find useful, in comments , or others can construct code.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -