Hi all,
just kind of a curious question about how best to program a variable that will determine a team's winning or losing streak.
So for example, let's there is data stored as follows:
which records whether a team won or a lost a game (1=win, 0=lose). Now let's say I want to calculate a variable which records their winning or losing streak. So for example, in this instance the variable would look like:
Streak
1
2
-1
1
2
-1
-2
1
2
3
any suggestions on how to do this?
I feel as though I have a basic idea of what needs to happen (using a retain statement for the streak variable and then perhaps indicating that if the current result = the lag(result) then streak+1 or streak-1 otherwise it needs to do the opposite streak - for example switching from a winning to a losing streak or vice versa). However, I'm not quite sure how to best accomplish this.
Any help would be appreciated - it's more of a curiosity than anything.
just kind of a curious question about how best to program a variable that will determine a team's winning or losing streak.
So for example, let's there is data stored as follows:
Code:
proc format;
value result 1='win' 0='lose';
run;
data streak;
input game result;
format result result.;
cards;
1 1
2 1
3 0
4 1
5 1
6 0
7 0
8 1
9 1
10 1
;
run;
Streak
1
2
-1
1
2
-1
-2
1
2
3
any suggestions on how to do this?
I feel as though I have a basic idea of what needs to happen (using a retain statement for the streak variable and then perhaps indicating that if the current result = the lag(result) then streak+1 or streak-1 otherwise it needs to do the opposite streak - for example switching from a winning to a losing streak or vice versa). However, I'm not quite sure how to best accomplish this.
Any help would be appreciated - it's more of a curiosity than anything.