来源:
http://blog.sina.com.cn/s/blog_8ab121f50100y3ec.html
option errors=1;
libname ff93 "F:\SAS Study ";
PROC IMPORT OUT= ff93.be
DATAFILE= "F:\SAS Study \be.dta"
DBMS=DTA REPLACE;
RUN;
data temp;set ff93.be;
year1=substr(accper,1,4);
year=input(year1,8.0);
if A300000>0;
rename A300000=BE;
drop accper year1;
run;
data temp1;set temp;run;
proc sort; by stkcd year;run;
PROC IMPORT OUT= ff93.mret
DATAFILE= "F:\SAS Study \mret.dta"
DBMS=DTA REPLACE;
RUN;
data ff93.mret;set ff93.mret;
year=substr(trdmnt,1,4)+0;
month=substr(trdmnt,6,2)+0;
run;
data stock;set ff93.mret;
run;
data stock2;set stock;
if month=12;
run;
proc sql;
create table BM as select
stock2.Msmvosd, temp1.*
from stock2, temp1
where stock2.stkcd=temp1.stkcd and stock2.year=temp1.year;
quit;
data bm1;set bm;
BM=BE/Msmvosd;
rename Msmvosd=mktcap;
if BM=. then delete;
run;
proc sort; by year; run;
proc univariate noprint; var BM; by year; output out=bm2 pctlpts=30 70 PCTLPRE=dec;run;
data bm3;merge bm1 bm2; by year;
if bm<=dec30 then HL=0;
if dec30<bm<=dec70 then HL=1;
if bm>dec70 then HL=2;
run;
proc sql;
create table bm4 as select
bm3.dec30, bm3.dec70, bm3.HL, stock.*
from bm3, stock
where bm3.stkcd=stock.stkcd and bm3.year=stock.year-1;
quit;
data me1;set stock;
if month=6;
size=Msmvosd;
run;
proc sort; by year;run;
proc univariate noprint; var size; by year; output out=size2 pctlpts=50 PCTLPRE=dec;run;
data size3; merge me1 size2; by year;
if size>dec50 then big=1;else big=0;
keep stkcd year big size;
run;
data size4;set bm4;
if month>=7 then rankyear=year;
if month<7 then rankyear=year-1;
run;
proc sql;
create table me3 as select
size3.size, size3.big, size4.*
from size3, size4
where size3.stkcd=size4.stkcd and size3.year=size4.rankyear;
quit;
run;
data bm7;set me3;
if big=0 and hl=0 then portnum=1;
if big=0 and hl=1 then portnum=2;
if big=0 and hl=2 then portnum=3;
if big=1 and hl=0 then portnum=4;
if big=1 and hl=1 then portnum=5;
if big=1 and hl=2 then portnum=6;
run;
proc sort; by year month portnum; run;
proc summary;weight msmvosd;
var mretwd;
by year month portnum;
output out=port3 mean=vwm;
run;
proc transpose data=port3 out=port4 prefix=vwmpret; by year month; var vwm;run;
data port5;set port4;
smb=mean(vwmpret1, vwmpret2,vwmpret3)-mean(vwmpret4, vwmpret5,vwmpret6);
hml=mean(vwmpret3, vwmpret6)-mean(vwmpret1, vwmpret4);
drop _name_;
run;
data rm;set ff93.mret;run;
proc sort; by year month stkcd;run;
proc summary;weight msmvosd;
var mretwd;
by year month;
output out=rm1 mean=rm;
run;
PROC IMPORT OUT= ff93.interest
DATAFILE= "F:\SAS Study \interest.dta"
DBMS=DTA REPLACE;
RUN;
data int;set ff93.interest;
year1=substr(trdmnt,1,4);
month1=substr(trdmnt,6,2);
year=input(year1,8.0);
month=input(month1,8.0);
drop trdmnt year1 month1;
run;
proc sql;
create table rmf1 as select
rm1.year, rm1.month,rm-rf as mktrf, rm1.rm, int.rf
from rm1, int
where rm1.year=int.year and rm1.month=int.month;
quit;
proc sql;
create table factors as select
rmf1.*, port5.smb, port5.hml
from rmf1, port5
where rmf1.year=port5.year and rmf1.month=port5.month;
quit;
data ff93.3factors;set factors;
run;