|
地板
楼主 |
发表于 2004-4-10 03:55:48
|
只看该作者
I can not test your data set, since my system does not support Chinese font. But, I think the following program will do whatever you want. Please pay attention that I do not care which two records form a pair, you can do some refinement. When you post this question, at least you have to tell us which variable represent charge and refund, I just guessed it here.
data aaa bbb(keep=yb_name yb_zydnu absamt index);
set aaa;
by yb_name;
if first.yb_name then index=0;
index+1;
output aaa;
absamt=abs(yb_zydnu);
output bbb;
run;
proc sort data=bbb;
by yb_name absamt;
run;
data bbb1 bbb2;
retain i j;
set bbb;
by yb_name absamt;
if first.absamt then do;
i=0; j=0;
end;
if yb_zydnu>=0 then do;
i+1;
output bbb1;
end;
else do;
j+1;
output bbb2;
end;
run;
proc sql;
create table keep as
select a.yb_name as ayb_name, b.yb_name as byb_name,
a.index as aindex, b.index as bindex,
a.i, b.j
from bbb1 a
full join bbb2 b
on a.yb_name=b.yb_name and
a.i =b.j;
quit;
data keep;
set keep;
if i=j then delete;
index=max(aindex,bindex);
if ayb_name ne ' ' then yb_name=ayb_name;
else yb_name=byb_name;
run;
proc sql;
create table aaa(drop=absamt index) as
select a.*
from aaa a, keep b
where a.yb_name=b.yb_name and
a.index =b.index
order by a.yb_name, a.index;
quit; |
|