为了这100金币,折腾了一下午,总算是把程序调试出来了。楼上的两个帖子的CODE完全不行,没那么简单。加了两个附件: 名字都是STOCK, 一个是SAS源程序(把后缀名改为.sas就可以运行),一个是运行结果(excel 文件)。半天时间的劳动,希望楼主信守承诺。我还指望着用这金币买书呢。如果有任何问题,站内联系。谢谢。以下是程序:
****author: thinman66*****************;
****date: 9/3/2013******************;
****purpose: earning 100 currencies on bbs.pingu.org******************;
data stock;
input stkcd date $ msmvttl pb;
cards;
1 199312 6000 2
1 199401 6300 2
1 199402 6200 2
1 199403 6000 3
1 199404 6400 3
1 199405 6700 3
1 199406 7000 5
1 199407 6500 5
1 199408 6800 5
1 199409 7100 2
1 199410 6750 2
1 199411 6000 2
1 199412 6000 2
1 199501 6300 2
1 199502 6200 2
1 199503 6000 3
1 199504 6400 3
1 199505 6700 3
1 199506 7000 5
1 199507 6500 5
1 199508 6800 5
1 199509 7100 2
1 199510 6750 2
1 199511 6000 2
3 199312 6000 2
3 199401 6300 2
3 199402 6200 2
3 199403 6000 3
3 199404 6400 3
3 199405 6700 3
3 199406 7000 5
3 199407 6500 5
3 199408 6800 5
3 199409 7100 2
3 199410 6750 2
3 199411 6000 2
3 199412 6000 2
3 199501 6300 2
3 199502 6200 2
3 199503 6000 3
3 199504 6400 3
3 199505 6700 3
3 199506 7000 5
3 199507 6500 5
3 199508 6800 5
3 199509 7100 2
3 199510 6750 2
3 199511 6000 2
;
run;
data stock;
set stock;
year=input(substr(date, 1, 4), ??best.);
month=input(substr(date, 5, 2), ??best.);
if month in (1, 2, 3) then quarter=1;
else if month in (4,5,6) then quarter=2;
else if month in (7,8,9) then quarter=3;
else if month in (10,11,12) then quarter=4;
run;
data stock;
set stock;
if month=3 then endmv1=msmvttl;
else if month=6 then endmv2=msmvttl;
else if month=9 then endmv3=msmvttl;
else if (month=11 or month=12) then endmv4=msmvttl;
run;
proc sort data=stock ;
by stkcd year month;
run;
data yr93;
set stock;
if year=1993 ;
run;
data yr94;
set stock;
if year=1994 ;
run;
data yr95;
set stock;
if year=1995 ;
run;
Data yr94( Drop = _: ) ;
Set yr94 ( Rename = ( endmv1 = _endmv1 endmv2 = _endmv2 endmv3 = _endmv3 endmv4 = _endmv4 ) ) ;
Retain endmv1 endmv2 endmv3 endmv4 ;
If not missing( _endmv1 ) then endmv1 = _endmv1 ;
If not missing( _endmv2 ) then endmv2 = _endmv2;
If not missing( _endmv3 ) then endmv3 = _endmv3;
If not missing( _endmv4 ) then endmv4 = _endmv4;
run ;
Data yr95( Drop = _: ) ;
Set yr95 ( Rename = ( endmv1 = _endmv1 endmv2 = _endmv2 endmv3 = _endmv3 endmv4 = _endmv4 ) ) ;
Retain endmv1 endmv2 endmv3 endmv4 ;
If not missing( _endmv1 ) then endmv1 = _endmv1 ;
If not missing( _endmv2 ) then endmv2 = _endmv2;
If not missing( _endmv3 ) then endmv3 = _endmv3;
If not missing( _endmv4 ) then endmv4 = _endmv4;
run ;
proc sort data=yr94;
by descending endmv1 descending endmv2 descending endmv3 descending endmv4 ;
run;
proc sort data=yr95;
by descending endmv1 descending endmv2 descending endmv3 descending endmv4 ;
run;
Data yr94( Drop = _: ) ;
Set yr94 ( Rename = ( endmv1 = _endmv1 endmv2 = _endmv2 endmv3 = _endmv3 endmv4 = _endmv4 ) ) ;
Retain endmv1 endmv2 endmv3 endmv4 ;
If not missing( _endmv1 ) then endmv1 = _endmv1 ;
If not missing( _endmv2 ) then endmv2 = _endmv2;
If not missing( _endmv3 ) then endmv3 = _endmv3;
If not missing( _endmv4 ) then endmv4 = _endmv4;
run ;
Data yr95( Drop = _: ) ;
Set yr95 ( Rename = ( endmv1 = _endmv1 endmv2 = _endmv2 endmv3 = _endmv3 endmv4 = _endmv4 ) ) ;
Retain endmv1 endmv2 endmv3 endmv4 ;
If not missing( _endmv1 ) then endmv1 = _endmv1 ;
If not missing( _endmv2 ) then endmv2 = _endmv2;
If not missing( _endmv3 ) then endmv3 = _endmv3;
If not missing( _endmv4 ) then endmv4 = _endmv4;
run ;
data combine;
set yr93 yr94 yr95;
run;
data combine;
set combine;
if quarter=4 then lastq=endmv3;
else if quarter=3 the lastq=endmv2;
else if quarter=2 the lastq=endmv1;
run;
data combine (drop=endmv1-endmv4);
set combine;
if (year=1994 and quarter=1) or (year=1995 and quarter=1) then lastq=endmv4;
***sjlv is 市净率 ***********************;
sjlv=( msmvttl/lastq)*pb;
run;
附件列表