23# sushe1527
下面是我按你的程序写的:
首先import data "fund"。
data fund1;
set fund;
date=mdy(input(substr(date,6,2),f2.),input(substr(date,9,2),f2.),input(substr(date,1,4),f4.)); /*因为我的数据里面的date是字符属性,不能用format yymmdd改*/
run;
proc sort data=fund1 out=fund01;
by stock date fund_code;
run;
proc sort data=fund01;
by stock date;
run;
data tmp;
set fund01;
by stock date;
mark=dif(year(date)*4+qtr(date));
if mark=1 then z+mark;
else z=0;
if z=3 then output;
run;
proc sql;
create table tmp1 as
select * from fund1 as left join tmp
on fund1.stock=tmp.stock and fund1.fund_code=tmp.fund_code;
quit;
data final;
merge fund1 tmp1;by stock date fund_code;
if mark=. then mark=0;drop z;
proc print data=final;
run;
出现了这个几个问题:
656 on fund1.stock=tmp.stock and fund1.fund_code=tmp.fund_code;
WARNING: Variable stock already exists on file WORK.TMP1.
WARNING: Variable date already exists on file WORK.TMP1.
WARNING: Variable fund_code already exists on file WORK.TMP1.
WARNING: Variable number_of_shares already exists on file WORK.TMP1.
WARNING: Variable proportion already exists on file WORK.TMP1.
并且最后处理的final,mark值全部都是0,但是我目测至少好几只股票都被某个基金连续持有了4个季度..
是不是我的程序哪里写错了.....?
