你好。不知你是否已经解决了问题。我也才学sas不久。我编了一个代码,可能比较繁琐,但是run了一下,符合你的要求。你可以试试。因为我觉得你可能需要把2010年和2011年的数据分开考虑。所以下面的代码只是得到10年的结果。如果需要11年的,只需将代码中2010改成2011即可。
data ds1 ;
infile 'c:\users\ds1.dat' dlm=',';
length account $5;
length name $18;
input account $ open_date name $ type $ ;
run;
data ds2 ;
infile 'c:\users\ds2.dat' dlm=',';
length trans_type $20;
input account $ trans_amount trans_date trans_type $;
run;
data ds22010;
set ds2;
transdate=put(trans_date,8.);
transyear=substr(transdate,1,4);
if transyear='2010';
run;
proc sort data=ds1;
by account;
run;
proc sort data=ds22010;
by account;
run;
data temp2010;
merge ds1(in=in1) ds22010(in=in2);
by account;
if in1 and in2;
if first.account then do;
totalamount=0;
number=0;
end;
do until(last.account ne .);
totalamount+trans_amount;
number+1;
end;
if last.account then output;
keep account open_date totalamount number;
run;
proc print data=temp2010;
run;