请教一个问题,我想做的需求是统计一个银行数据,每个用户(ID)每次服务类型(deposit 或者withdraw)的总和,就是每个用户交易类型为deposit的总和是多少,交易类型为withdraw的总和又是多少,可是我跑出来的程序结果总是错误的,统计不对,我真不知道错哪里了,跪求啊,谢谢。
data zsh;
input ID $ date:date9. type $;
format date:date9.;
cards;
0001 01may2001 deposit
0002 01may2001 withdraw
0003 02may2001 withdraw
0001 18may2001 deposit
0001 27may2001 deposit
0002 27may2001 deposit
0003 04may2001 withdraw
;
run;
proc sort data=zsh out=zsh2;
by ID type;
run;
data zsh3;
set zsh2;
by id type;
retain num 0 odd 0;
if first.id then do;
if type='deposit' then num=1;
else if type='withdraw' then odd=1;
end;
else do;
if type='deposit' then num+1;
else if type='withdraw' then odd+1;
end;
if last.id then output;
run;