嗨:我正在处理棒球数据集。我想算一个团队获胜的连胜纪录。我创建了一个名为win的变量,如果团队A获胜则为1,否则为0.我想创建一个名为winstreak的变量,如果团队A获胜1次,则为1,如果团队A连续获胜2次,则是2,如果A队失败则再次回到0。到目前为止,我已经尝试过:
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;
代码不起作用,因为winstreak只显示与PHIWIN相同的值。请帮忙!