次のサンプルデータがあります。
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' にする必要があります。2 番目のデータ ステップで resulthistory 変数を宣言しましたが、同じユーザー名の場合、新しい結果を resulthistory 変数に連結できないようです。問題は、文字列変数を使用していることですか、それとも前の行から何かを参照しようとしていることですか?
これについて助けてくれてありがとう。