|
|
地板

楼主 |
发表于 2009-9-9 18:09:47
|
只看该作者
Re: 交易记录修正问题
[code:3ua8ek3m]data raw;
input company date yymmdd10. stock $ share;
format date yymmdd10.;
datalines;
1 2003-6-30 000001 34567
1 2003-6-30 000002 56789
1 2003-6-30 000003 12345
2 2003-6-30 000001 345
2 2003-6-30 000002 123
1 2004-6-30 000001 12345
1 2004-6-30 000003 54321
;
proc sort data=raw out=temp;
by company stock date;
run;
data stock_start stock_end;
set temp;
by company stock;
if first.stock then output stock_start;
if last.stock then output stock_end;
run;
proc sql noprint;
create table temp as
select a.company, a.stock, a.date as date_start, a.share as share_start,
b.date as date_end, b.share as share_end,
case share_start-share_end
when 0 then -share_start
else share_start-share_end
end as share_diff
from stock_start a, stock_end b
where a.company=b.company and a.stock=b.stock;
quit;[/code:3ua8ek3m] |
|