是以下这个结果,还是每个stkcd只计算最大的连续半年数?
- proc import out=fund
- datafile="C:/fund.xls"
- dbms=excel replace;
- run;
- proc sort data=fund;by fundcode stkcd year ym;run;
- data fund1;
- set fund;
- by fundcode stkcd year ym;
- retain lastyear lastym cnt index;
- if first.stkcd then do;
- cnt=1;
- index=0;
- lastyear=.;
- lastym=.;
- end;
- else if (year-lastyear)*2+ym-lastym=1 then cnt=cnt+1;
- else cnt=1;
- if cnt=1 then index=index+1;
- lastyear=year;
- lastym=ym;
- drop lastyear lastym;
- proc sort;by fundcode stkcd index descending cnt;
- run;
- data fund2;
- set fund1;
- by fundcode stkcd index descending cnt;
- retain ttcnt;
- if first.index then ttcnt=cnt;
- drop index;
- proc sort;by fundcode stkcd year ym;
- run;
复制代码