0

Hi: I am processing baseball dataset. I want to count the winning streak of a team winning. I created a variable called win, if team A wins it is 1, else it is 0. I want to create a variable called winstreak, if team A wins 1 time, it is 1, if team A wins 2 in a row, it is 2, if team A loses it goes back to 0 again. So far I have tried:

data phi2002;
  set phi2002;
  retain winstreak;

  if (VisitingTeam = "PHI" and VisitorRunsScored > HomeRunsScore)
    then PHIWIN = 1;
  else if (HomeTeam = "PHI" and HomeRunsScore > VisitorRunsScored)
    then PHIWIN = 1;
  else PHIWIN = 0;

  if PHIWIN = 1 then winstreak =+1;
  else winstreak = 0;
run;

The code doesnt work, since winstreak only shows the same value as PHIWIN. Please help!

Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61
Richard Li
  • 21
  • 1
  • 9

0 Answers0