我有以下示例数据:
data have;
input username $ betdate : datetime. winnings;
retain username dateonly bedate result;
dateOnly = datepart(betdate) ;
format betdate DATETIME.;
format dateOnly ddmmyy8.;
datalines;
player1 12NOV2008:12:04:01 -10
player1 12NOV2008:19:03:44 50
player2 07NOV2008:14:03:33 -50
player2 05NOV2008:09:00:00 -100
run;
PROC PRINT; RUN;
proc sort data=have;
by username betdate;
run;
data want;
set have;
by username dateOnly betdate;
retain username dateonly bedate winnings winner resulthistory;
if winnings > 0 then winner = 'W';
if winnings <= 0 then winner = 'L';
if first.winlose then resulthistory=winner;
else if first.betdate then resulthistory=resulthistory||winner;
PROC PRINT; RUN;
我想在最后一列中显示累积结果历史记录。对于 player1,这将是 'WL';对于 player2,它应该是 'LL'。我在第二个数据步骤中声明了 resulthistory 变量,但如果它是相同的用户名,似乎无法将新结果连接到 resulthistory 变量。问题是我正在使用字符串变量还是我试图从前一行引用某些内容?
感谢您对此的任何帮助。