BookmarkSubscribeRSS Feed
rick_b
Fluorite | Level 6

Hi, all. My last post (https://communities.sas.com/t5/SAS-Programming/Calculate-How-Prior-Bet-Profits-Losses-Influence-Futu...) went unsolved (thanks very much to those who gave it a look). I am clarifying here and asking for additional help. Unnecessary columns have been removed and desired calculations are now described within the datalines.

 

Description: When a gambler decides how much to bet, their decision is influenced by their prior wager outcomes (perhaps they start to double down if they have sustained losses, for example), and I am trying to examine how NFL gamblers' prior betting profits/losses influence their next-round-of-betting behavior.  I need a rolling sum of the profits/losses from just the last very round of completed NFL events as shown below.

 

data WORK.bets (drop=product_account_id bet_id eleven_digit_account_id net_stake);
infile datalines;
input product_account_id:$10. bet_id:$15. eleven_digit_account_id:$11. net_stake:3. bet_date:mmddyy10.
bet_time:time8. bet_day_of_week:$10. event_date:mmddyy10. event_time:time8.
event_day_of_week:$10. bet_profit:5. desired_output:5.;
format bet_date mmddyy10. bet_time time8. event_date mmddyy10. event_time time8.;

*Note: games (aka 'events') last three hours from start to finish;
*Note: there are many gamblers, each with a unique product_account_id, so summing needs to begin anew when a new product_account_id arrives;

datalines;
12101170 81758848.516 00012101170 2 10/9/2023 20:29 Monday 10/9/2023 20:16 Monday 2 .
12101170 81758939.516 00012101170 3 10/9/2023 20:30 Monday 10/9/2023 20:16 Monday 2.4 .
12101170 81759255.516 00012101170 2 10/9/2023 20:34 Monday 10/9/2023 20:16 Monday 1.68 .
12101170 81760925.516 00012101170 3 10/9/2023 20:48 Monday 10/9/2023 20:16 Monday 2.61 .
12101170 81764937.516 00012101170 3 10/9/2023 21:26 Monday 10/9/2023 20:16 Monday -3 .
12101170 81768542.516 00012101170 3 10/9/2023 22:03 Monday 10/9/2023 20:16 Monday 2.64 .
12101170 82231252.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 13:01 Sunday 2.73 8.33 *the Monday events have expired and the payouts are now known, desired_output is the sum of the first six rows of bets*
12101170 82231251.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 13:05 Sunday 2.73 8.33 *the last known event outcomes were again last Monday, same calculation*
12101170 82231250.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 13:05 Sunday 2.46 8.33 *same here*
12101170 82231253.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 16:26 Sunday 2.85 8.33 *same here*
12101170 82231254.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 16:27 Sunday -3 8.33 *same here*
12101170 82231345.516 00012101170 3 10/14/2023 14:39 Saturday 10/15/2023 13:05 Sunday 2.46 8.33 *same here*
12101170 82231346.516 00012101170 3 10/14/2023 14:39 Saturday 10/15/2023 13:05 Sunday 2.73 8.33 *same here*
12101170 82231347.516 00012101170 3 10/14/2023 14:39 Saturday 10/15/2023 16:26 Sunday 2.85 8.33 *same here*
12101170 82231348.516 00012101170 3 10/14/2023 14:39 Saturday 10/15/2023 16:27 Sunday -3 8.33 *same here*
12101170 82231466.516 00012101170 3 10/14/2023 14:40 Saturday 10/15/2023 13:05 Sunday 2.73 8.33 *etc....*
12101170 82231465.516 00012101170 3 10/14/2023 14:40 Saturday 10/15/2023 13:05 Sunday 2.46 8.33
12101170 82231467.516 00012101170 3 10/14/2023 14:40 Saturday 10/15/2023 16:26 Sunday 2.85 8.33
12101170 82348229.516 00012101170 3 10/15/2023 7:49 Sunday 10/15/2023 9:35 Sunday -3 8.33
12101170 82348234.516 00012101170 3 10/15/2023 7:49 Sunday 10/15/2023 13:01 Sunday -3 8.33
12101170 82348231.516 00012101170 3 10/15/2023 7:49 Sunday 10/15/2023 13:01 Sunday 2.61 8.33
12101170 82348230.516 00012101170 3 10/15/2023 7:49 Sunday 10/15/2023 13:03 Sunday -3 8.33
12101170 82348233.516 00012101170 3 10/15/2023 7:49 Sunday 10/15/2023 13:04 Sunday 2.55 8.33
12101170 82348235.516 00012101170 3 10/15/2023 7:49 Sunday 10/15/2023 13:05 Sunday 2.94 8.33
12101170 82348232.516 00012101170 3 10/15/2023 7:49 Sunday 10/15/2023 13:05 Sunday 2.73 8.33
12101170 82348267.516 00012101170 3 10/15/2023 7:50 Sunday 10/15/2023 13:01 Sunday 2.61 8.33
12101170 82348270.516 00012101170 3 10/15/2023 7:50 Sunday 10/15/2023 13:01 Sunday -3 8.33
12101170 82348266.516 00012101170 3 10/15/2023 7:50 Sunday 10/15/2023 13:03 Sunday -3 8.33
12101170 82348269.516 00012101170 3 10/15/2023 7:50 Sunday 10/15/2023 13:04 Sunday 2.55 8.33
12101170 82348271.516 00012101170 3 10/15/2023 7:50 Sunday 10/15/2023 13:05 Sunday 2.94 8.33
12101170 82348268.516 00012101170 3 10/15/2023 7:50 Sunday 10/15/2023 13:05 Sunday 2.73 8.33
12101170 82348305.516 00012101170 3 10/15/2023 7:51 Sunday 10/15/2023 13:01 Sunday -3 8.33
12101170 82348307.516 00012101170 3 10/15/2023 7:51 Sunday 10/15/2023 13:01 Sunday 2.85 8.33
12101170 82348308.516 00012101170 3 10/15/2023 7:51 Sunday 10/15/2023 13:03 Sunday -3 8.33
12101170 82348306.516 00012101170 3 10/15/2023 7:51 Sunday 10/15/2023 13:05 Sunday 2.94 8.33
12101170 82348304.516 00012101170 3 10/15/2023 7:51 Sunday 10/15/2023 13:05 Sunday 2.73 8.33
12101170 82439386.516 00012101170 3 10/15/2023 13:14 Sunday 10/15/2023 13:04 Sunday -3 -3 *this bet was placed on Sunday at ~1:00 p.m., the last event in which the gambler experienced a payout began Sunday at 9:35 a.m. and ended Sunday at 12:35 p.m., that bet's profit was -3*
12101170 82439455.516 00012101170 3 10/15/2023 13:14 Sunday 10/15/2023 13:01 Sunday 2.73 -3 *same here*
12101170 82439531.516 00012101170 3 10/15/2023 13:14 Sunday 10/15/2023 13:05 Sunday 2.73 -3 *same here*
12101170 82478787.516 00012101170 3 10/15/2023 16:02 Sunday 10/15/2023 16:06 Sunday 2.46 33.03 *this bet was placed on Sunday at ~4:00 p.m., the most recent profits are from events played on Sunday from ~1:00 to ~4:00, profits are the sum of rows 7-18 plus rows 20-36 (profit from row 19 has already been captured)*
12101170 82478786.516 00012101170 3 10/15/2023 16:02 Sunday 10/15/2023 16:26 Sunday 2.73 33.03
12101170 82478788.516 00012101170 3 10/15/2023 16:02 Sunday 10/15/2023 16:26 Sunday 2.73 33.03
12101170 82478789.516 00012101170 3 10/15/2023 16:02 Sunday 10/15/2023 16:27 Sunday -3 33.03
12101170 82478974.516 00012101170 3 10/15/2023 16:02 Sunday 10/15/2023 16:06 Sunday 2.46 33.03
12101170 82478973.516 00012101170 3 10/15/2023 16:02 Sunday 10/15/2023 16:26 Sunday 2.73 33.03
12101170 82478975.516 00012101170 3 10/15/2023 16:02 Sunday 10/15/2023 16:27 Sunday -3 33.03
12101170 82479827.516 00012101170 6 10/15/2023 16:03 Sunday 10/15/2023 16:26 Sunday 5.46 33.03
12101170 82479826.516 00012101170 6 10/15/2023 16:03 Sunday 10/15/2023 16:27 Sunday -6 33.03
12101170 82482465.516 00012101170 3 10/15/2023 16:07 Sunday 10/15/2023 16:26 Sunday 2.73 33.03
12101170 82493073.516 00012101170 2 10/15/2023 16:34 Sunday 10/15/2023 16:26 Sunday 1.92 33.03
12101170 82550551.516 00012101170 2 10/15/2023 20:57 Sunday 10/15/2023 20:23 Sunday -2 11.22 *this bet was placed on Sunday at ~8:00 p.m., the last profits were from games played earlier that day at 4:00 p.m. (rows 40-50)*
12101170 82553228.516 00012101170 2 10/15/2023 21:23 Sunday 10/15/2023 20:23 Sunday -2 11.22 *same here*
12101170 82555259.516 00012101170 2 10/15/2023 21:44 Sunday 10/15/2023 20:23 Sunday -2 11.22 *same here*
12101170 82646184.516 00012101170 3 10/16/2023 20:25 Monday 10/16/2023 20:16 Monday -3 -6
12101170 82647533.516 00012101170 3 10/16/2023 20:34 Monday 10/16/2023 20:16 Monday -3 -6
12101170 82647545.516 00012101170 6 10/16/2023 20:34 Monday 10/16/2023 20:16 Monday -6 -6
12101170 82899789.516 00012101170 2 10/19/2023 20:23 Thursday 10/19/2023 20:16 Thursday 1.96 -12
12101170 82904693.516 00012101170 3 10/19/2023 20:59 Thursday 10/19/2023 20:16 Thursday 2.64 -12
12101170 82906147.516 00012101170 3 10/19/2023 21:08 Thursday 10/19/2023 20:16 Thursday -3 -12
12101170 83235976.516 00012101170 3 10/22/2023 9:23 Sunday 10/22/2023 13:02 Sunday -3 1.6
12101170 83235974.516 00012101170 3 10/22/2023 9:23 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83236035.516 00012101170 3 10/22/2023 9:24 Sunday 10/22/2023 13:02 Sunday -3 1.6
12101170 83236033.516 00012101170 3 10/22/2023 9:24 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83236190.516 00012101170 3 10/22/2023 9:25 Sunday 10/22/2023 13:02 Sunday -3 1.6
12101170 83237824.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 13:01 Sunday -3 1.6
12101170 83237827.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 13:02 Sunday -3 1.6
12101170 83237823.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83237825.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 13:05 Sunday 2.64 1.6
12101170 83237829.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 16:06 Sunday -3 1.6
12101170 83237922.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 13:01 Sunday -3 1.6
12101170 83237924.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 13:02 Sunday -3 1.6
12101170 83237921.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83237926.516 00012101170 3 10/22/2023 9:36 Sunday 10/22/2023 16:06 Sunday -3 1.6
12101170 83238000.516 00012101170 3 10/22/2023 9:37 Sunday 10/22/2023 13:01 Sunday -3 1.6
12101170 83238002.516 00012101170 3 10/22/2023 9:37 Sunday 10/22/2023 13:02 Sunday -3 1.6
12101170 83237999.516 00012101170 3 10/22/2023 9:37 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83238004.516 00012101170 3 10/22/2023 9:37 Sunday 10/22/2023 16:06 Sunday -3 1.6
12101170 83238165.516 00012101170 3 10/22/2023 9:38 Sunday 10/22/2023 13:01 Sunday -3 1.6
12101170 83238164.516 00012101170 3 10/22/2023 9:38 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83238170.516 00012101170 3 10/22/2023 9:38 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83238167.516 00012101170 3 10/22/2023 9:38 Sunday 10/22/2023 16:06 Sunday -3 1.6
12101170 83238244.516 00012101170 3 10/22/2023 9:38 Sunday 10/22/2023 13:01 Sunday -3 1.6
12101170 83238249.516 00012101170 3 10/22/2023 9:38 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83238246.516 00012101170 3 10/22/2023 9:38 Sunday 10/22/2023 16:06 Sunday -3 1.6
12101170 83238318.516 00012101170 3 10/22/2023 9:39 Sunday 10/22/2023 13:03 Sunday -3 1.6
12101170 83238315.516 00012101170 3 10/22/2023 9:39 Sunday 10/22/2023 16:06 Sunday -3 1.6
12101170 83263216.516 00012101170 6 10/22/2023 11:14 Sunday 10/22/2023 13:02 Sunday -6 1.6
12101170 83395974.516 00012101170 3 10/22/2023 16:35 Sunday 10/22/2023 16:06 Sunday -3 -63.36 *only events at 1:00 p.m. earlier on this day should be included in the sum (rows 60-87 excluding rows 69,73,77,81,84,86)*
50001170 83395975.52 50001170 3 10/21/2023 16:35 Saturday 10/22/2023 13:06 Sunday -3 . *new gambler*
50001170 83395972.52 50001170 3 10/21/2023 16:35 Saturday 10/22/2023 13:26 Sunday 2.55 . *new gambler*
50001170 83395973.52 50001170 3 10/21/2023 16:35 Saturday 10/22/2023 13:26 Sunday 2.55 . *new gambler*
50001170 83398125.52 50001170 3 10/21/2023 16:44 Saturday 10/22/2023 13:06 Sunday -3 . *new gambler*
50001170 83398126.52 50001170 3 10/21/2023 16:44 Saturday 10/22/2023 13:06 Sunday -3 . *new gambler*
50001170 83398127.52 50001170 3 10/23/2023 16:44 Monday 10/29/2023 16:26 Sunday 2.64 -3.9 *sum of last 5 rows*
50001170 83398128.52 50001170 3 10/23/2023 16:44 Monday 10/29/2023 16:26 Sunday 2.82 -3.9 *same calculation as above row*
50001170 83403470.52 50001170 3 10/23/2023 17:13 Monday 10/29/2023 16:06 Sunday -3 -3.9 *Etc.*
50001170 83403472.52 50001170 3 10/23/2023 17:13 Monday 10/29/2023 16:26 Sunday -3 -3.9
50001170 83408418.52 50001170 3 10/23/2023 17:44 Monday 10/29/2023 16:26 Sunday -3 -3.9
50001170 83417137.52 50001170 3 10/23/2023 18:35 Monday 10/29/2023 16:06 Sunday -3 -3.9
50001170 83417136.52 50001170 3 10/29/2023 12:35 Sunday 10/29/2023 16:06 Sunday 1.71 -3.9
50001170 83417135.52 50001170 3 10/29/2023 12:35 Sunday 10/29/2023 16:26 Sunday -3 -3.9
50001170 83417134.52 50001170 3 10/29/2023 12:35 Sunday 10/29/2023 16:26 Sunday 1.89 -3.9
50001170 83417192.52 50001170 3 10/29/2023 12:35 Sunday 10/29/2023 16:26 Sunday -3 -3.9
50001170 83540873.52 50001170 3 10/29/2023 19:35 Sunday 10/29/2023 20:16 Sunday -3 -8.94 *sum of profits for events on prior 10 rows*
50001170 83575341.52 50001170 3 10/29/2023 19:35 Sunday 10/29/2023 20:16 Sunday -3 -8.94 *same calculation as above row*
50001170 83576079.52 50001170 3 10/29/2023 19:35 Sunday 10/29/2023 20:16 Sunday -3 -8.94 *same calculation as above row*
proc print;
run;

7 REPLIES 7
ballardw
Super User

Suggestion:

Provide a smaller example data set.

Provide at least two different accounts.

 

If a variable doesn't contribute to the problem you are asking us to provide a solution for remove it (for the example of how to calculate something).

If you have Bet_date then Bet_day_of_week is redundant as you can calculate that from Bet_date if needed for example.

 

Define how we can tell what a " last very round of completed NFL events" is determined by the values in the (new) provided example data.

My concern with the definition of "event" is NFL has many games running at the same time or to place bets on before hand. So how can we really  tell what constitutes an event without a clear statement.

rick_b
Fluorite | Level 6

Thank you for your suggestions. It is difficult to find a subsample that better illustrates the nuances than the one I provided. I included bet and event days in an attempt to make the visual logic more understandable. The last issue you ask me to clarify is the one that I really need help solving - identifying the last completed 'block' of bets. Games last three hours and begin only on certain days/times, but betting is continuous, so I need to identify a way to efficiently establish the last completed round of bet-on games prior to each bet. I've tried establishing bet and event blocks but keep encountering problems when trying to properly sum just the most recent set of bet outcomes. Here is my current approach (which is incomplete but may help stimulate new ideas). I will amend with another gamblers' bets in a moment...

 


if event_dayofweek='Monday' and event_hour=13 then event_block=1;
if event_dayofweek='Monday' and event_hour=16 then event_block=2;
if event_dayofweek='Monday' and event_hour=20 then event_block=3;

if event_dayofweek='Tuesday' then event_block=4;*week 15 2021;

if event_dayofweek='Thursday' and event_hour=12 then event_block=5;
if event_dayofweek='Thursday' and event_hour=16 then event_block=6;
if event_dayofweek='Thursday' and event_hour=20 then event_block=7;

if event_dayofweek='Friday' then event_block=8;

if event_dayofweek='Saturday' and event_hour=13 then event_block=9;
if event_dayofweek='Saturday' and event_hour=16 then event_block=10;
if event_dayofweek='Saturday' and event_hour=20 then event_block=11;

if event_dayofweek='Sunday' and event_hour=9 then event_block=12;
if event_dayofweek='Sunday' and event_hour=13 then event_block=13;
if event_dayofweek='Sunday' and event_hour=16 then event_block=14;
if event_dayofweek='Sunday' and event_hour=19 then event_block=15;
if event_dayofweek='Sunday' and event_hour=20 then event_block=15;

*;

if bet_dayofweek='Monday' and bet_hour<16 then last_event_block_completed=15;

if bet_dayofweek='Monday' and bet_hour ge 16 and bet_hour<20 then last_event_block_completed=1;
if bet_dayofweek='Monday' and bet_hour ge 20 and bet_hour<23 then last_event_block_completed=2;
if bet_dayofweek='Monday' and bet_hour ge 23 then last_event_block_completed=3;

if bet_dayofweek='Tuesday' then last_event_block_completed=3;
if bet_dayofweek='Wednesday' then last_event_block_completed=3;

if bet_dayofweek='Thursday' and bet_hour<16 then last_event_block_completed=4;
if bet_dayofweek='Thursday' and bet_hour ge 16 and bet_hour<20 then last_event_block_completed=5;
if bet_dayofweek='Thursday' and bet_hour ge 20 and bet_hour le 23 then last_event_block_completed=6;
if bet_dayofweek='Thursday' and bet_hour ge 23 then last_event_block_completed=7;

if bet_dayofweek='Friday' then last_event_block_completed=7;

if bet_dayofweek='Saturday' and bet_hour<16 then last_event_block_completed=8;
if bet_dayofweek='Saturday' and bet_hour ge 16 and bet_hour<20 then last_event_block_completed=9;
if bet_dayofweek='Saturday' and bet_hour ge 20 and bet_hour<23 then last_event_block_completed=10;
if bet_dayofweek='Saturday' and bet_hour ge 23 then last_event_block_completed=11;

if bet_dayofweek='Sunday' and bet_hour<13 then last_event_block_completed=11;
if bet_dayofweek='Sunday' and bet_hour ge 13 and bet_hour<16 then last_event_block_completed=12;
if bet_dayofweek='Sunday' and bet_hour ge 16 and bet_hour<20 then last_event_block_completed=13;
if bet_dayofweek='Sunday' and bet_hour ge 20 and bet_hour<23 then last_event_block_completed=14;
if bet_dayofweek='Sunday' and bet_hour ge 23 then last_event_block_completed=15;

 

rick_b
Fluorite | Level 6

I have now modified the original datalines to reflect two gamblers.

ballardw
Super User

Having to guess what an event might be is and indicator that perhaps you don't have all the data. Or you have a research question phrased in such a way that the data will not support a resolution.

 

Lets consider one approach: duration of time between "events". I am not sure that the "bet date" actually contributes much to this but then I have no understanding of the actual data as it feels very incomplete (what was actually bet on is missing).

This might be one way to look at intervals.

Note creation of datetime valued variables in the data step with the DHMS function and much smaller set just as an example.

data WORK.bets (drop=eleven_digit_account_id);
infile datalines ;
input product_account_id:$10. bet_id:$15. eleven_digit_account_id:$11. net_stake:3. bet_date:mmddyy10.
bet_time:time8. bet_day_of_week:$10. event_date:mmddyy10. event_time:time8.
event_day_of_week:$10. bet_profit:5. desired_output:5.;
format bet_date mmddyy10. bet_time time8. event_date mmddyy10. event_time time8.;

*Note: games (aka 'events') last three hours from start to finish;
*Note: there are many gamblers, each with a unique product_account_id, so summing needs to begin anew when a new product_account_id arrives;
bet_dt = dhms(bet_date,0,0,bet_time);
event_dt = dhms(event_date,0,0,event_time);
format bet_dt event_dt datetime20.;
datalines;
12101170 81758848.516 00012101170 2 10/9/2023 20:29 Monday 10/9/2023 20:16 Monday 2 .
12101170 81758939.516 00012101170 3 10/9/2023 20:30 Monday 10/9/2023 20:16 Monday 2.4 .
12101170 81759255.516 00012101170 2 10/9/2023 20:34 Monday 10/9/2023 20:16 Monday 1.68 .
12101170 81760925.516 00012101170 3 10/9/2023 20:48 Monday 10/9/2023 20:16 Monday 2.61 .
12101170 81764937.516 00012101170 3 10/9/2023 21:26 Monday 10/9/2023 20:16 Monday -3 .
12101170 81768542.516 00012101170 3 10/9/2023 22:03 Monday 10/9/2023 20:16 Monday 2.64 .
12101170 82231252.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 13:01 Sunday 2.73 8.33 *the Monday events have expired and the payouts are now known, desired_output is the sum of the first six rows of bets*
12101170 82231251.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 13:05 Sunday 2.73 8.33 *the last known event outcomes were again last Monday, same calculation*
12101170 82231250.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 13:05 Sunday 2.46 8.33 *same here*
12101170 82231253.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 16:26 Sunday 2.85 8.33 *same here*
12101170 82231254.516 00012101170 3 10/14/2023 14:38 Saturday 10/15/2023 16:27 Sunday -3 8.33 *same here*
12101170 82231345.516 00012101170 3 10/14/2023 14:39 Saturday 10/15/2023 13:05 Sunday 2.46 8.33 *same here*
;

proc sort data=work.bets;
   by product_account_id event_dt;
run;

data work.example;
   set work.bets (drop=bet_date bet_time bet_day_of_week event_date event_time desired_output event_day_of_week ) ;
   by product_account_id event_dt;
   retain Event_ID;
   event_time_dif=dif(event_dt);
   if first.product_account_id then event_id=1;
   /*event_time_dif is number of seconts between "events". 
     3600 would be one hour for example
   */
   else if event_time_dif>3600 then event_id+1;
run; 

This is an attempt to "group" events together as that seems to be part of what you are doing. It just uses a different metric.

You seem to have a fair amount of data. You might be able to model the Event_time_dif per Product_account_id value (if that represents a person) to see the likely distribution of time between events (or bets). So you might take a pass through the data to develop a per person interval to use in setting a boundary between events.

Any way, IF such an event_id can be generated this way then summing is EASY (once the Event_ID is decided upon):

proc summary data=work.example nway;
    by product_account_id Event_id;
    var  bet_profit;
    output out=work.profit_sum sum=Profit_sum;
run;

Your "example" kept saying things that are not programmable in a general sense.

 

I would be tempted to play around with both an Event_time and a Bet_time interval to see about what is likely to represent an "event".

 

What the second data set does, assuming the base data is sorted correctly:

The BY statement adds automatic variables that indicate whether an observation is the first (or last) of a BY group. These are only available in a data step and are not added to the data. The values are 1 (if the first or last) or 0 otherwisse and as such can be used as logical variables. SAS treats 1 as true and 0 as false. The main purpose here is to reset the event counter for a new 'product_id'.

The DIF function returns the difference between the current value of the variable that in the previous observation. So with a single datetime valued variable we have number of seconds between "event" times.

I am supposing that larger differences are more likely to indicate a different "event". Finding a boundary for consistency is a chore.

 

The proc summary creates a total based on  the product_id and the Event_id. If you need that value on each observation of your original data then you would merge (or join) it back base on the product_id Event_id.

I suspect that your analysis might be doable with just the product and event ids unless there is something else not stated yet.

 

If this were my project and I was getting paid to analyze this I would suggest to whoever provided this data that perhaps there is another bit of data that identifies the "event" and suggest that should be included instead of having to guess what is a related group of observations.

 

rick_b
Fluorite | Level 6

I appreciate your efforts, ballardw. Maybe we are getting closer. I will think on it more.

 

Events do have names (e.g, green bay packers at las vegas raiders) which I omitted (along with a series of other variables), so I could easily assign a unique number, but the trick is to identify only those event_IDs that have most recently concluded so that only the most recent round of profits/losses are used to study how gamblers adjust their betting strategies via new wagers.

 

I was able to write code that looks back over a range of days to sum profits, but without some sort of if/then logic to identify which specific events should be included in the sum I am unable identify just the most recent round of betting profits/losses. It's an approximation but I need something more fine-tuned. Maybe it helps?

 

data want(drop=_:);
 
if _n_=1 then do;
if 0 then set bets (rename=(event_date_in_EST=_event_date_in_EST bet_profit=_bet_profit));
dcl hash h1(dataset:'bets(keep=eleven_digit_account_id event_date_in_EST bet_profit rename=(event_date_in_EST=_event_date_in_EST bet_profit=_bet_profit))',multidata:'y');
h1.defineKey('eleven_digit_account_id');
h1.defineData('_event_date_in_EST','_bet_profit');
h1.defineDone();
    end;
 
set bets;
 
bet_profit1_calc=0;
bet_profit7_calc=0;
bet_profit30_calc=0;
bet_profit2_7_calc=0;
bet_profit8_30_calc=0;
 
do while(h1.do_over() eq 0);
  if event_date_in_EST>_event_date_in_EST then do;
if _event_date_in_EST ge event_date_in_EST-1 then bet_profit1_calc=sum(bet_profit1_calc,_bet_profit);
if _event_date_in_EST ge event_date_in_EST-7 then bet_profit7_calc=sum(bet_profit7_calc,_bet_profit);
if _event_date_in_EST ge event_date_in_EST-30 then bet_profit30_calc=sum(bet_profit30_calc,_bet_profit);
if _event_date_in_EST<event_date_in_EST-1 and _event_date_in_EST ge event_date_in_EST-7 then bet_profit2_7_calc=sum(bet_profit2_7_calc,_bet_profit);
if _event_date_in_EST<event_date_in_EST-7 and _event_date_in_EST ge event_date_in_EST-30 then bet_profit8_30_calc=sum(bet_profit8_30_calc,_bet_profit);
  end;
end;
 
run;
ballardw
Super User

You are at a point where I can't help any more.

 

You obviously have a concept of "most recent" that I cannot follow as it appears to have a lot of censoring of data involved with rules either not clearly stated or possibly not allowed to share.

rick_b
Fluorite | Level 6
It's become clear that I have a lot more work to do outside of SAS coding. Thank you for your guidance.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 391 views
  • 2 likes
  • 2 in conversation