如何汇总以下示例数据以提供客户级别的计算?我正在使用“通过处理”的数据步骤,但我不确定是否应该将其分成两个数据步骤。
我需要为每个球员提取 first type
、 first price
、 count of types
、 uniqueprices
计数、 football 投注计数和棒球投注计数。
我似乎无法在同一个数据步骤中将type
和结合起来。price
data have;
input username $ betdate : datetime. stake type $ price sport $;
dateOnly = datepart(betdate) ;
format betdate DATETIME.;
format dateOnly ddmmyy8.;
datalines;
player1 12NOV2008:12:04:01 90 SGL 5 SOCCER
player1 04NOV2008:09:03:44 30 SGL 4 SOCCER
player2 07NOV2008:14:03:33 120 SGL 5 SOCCER
player1 05NOV2008:09:00:00 50 SGL 4 SOCCER
player1 05NOV2008:09:05:00 30 DBL 3 BASEBALL
player1 05NOV2008:09:00:05 20 DBL 4 BASEBALL
player2 09NOV2008:10:05:10 10 DBL 5 BASEBALL
player2 15NOV2008:15:05:33 35 DBL 5 BASEBALL
player1 15NOV2008:15:05:33 35 TBL 5 BASEBALL
player1 15NOV2008:15:05:33 35 SGL 4 BASEBALL
run;
proc print;run;
proc sort data=have; by username dateonly betdate type price; run;
data want;
set have;
retain typecount pricecount firsttype firstprice soccercount baseballcount;
by username dateonly betdate;
if first.username then eventTime = 0;
if first.betdate then eventTime + 1;
if first.username then soccercount=0;
if first.username then baseballcount=0;
if index(upcase(sport),'SOCCER') and eventtime <=5 then soccercount+1;
else if eventtime <=5 then baseballcount+1;
if first.username and eventtime =1 then firsttype=type;
else if eventtime =1 then firsttype=type;
if first.username and eventtime =1 then firstprice=price;
else if eventtime =1 then firstprice=price;
if first.username then typecount=0;
if first.type then typecount+1;
if first.username then pricecount=0;
if first.price and eventtime <=5 then pricecount+1;
IF last.username THEN OUTPUT;
keep username soccercount baseballcount firsttype firstprice typecount pricecount;
run;
proc print;run;