jingju11 发表于 2013-1-19 08:27
Thank Pobel again. To fit my code, i did some minor adjustment. To my surprise, there is no optimal ...
- this is the code from myself. No significant gain to the previous. it is just for sharing. Jingju
-
- data rate_all2nonRrr2;
- set rate_all2nonRrr1;
- by clnt_no acct_ref_no;
- retain s0;
- if (first.acct_ref_no) then do;
- s0 =qtr_dt; s =0;
- end;
- s ++1;
- if (s >3) then delete; /*once s adds upto 3, delete any following records till the next id*/
- if (intnx('month', s0, 3*(s-1), 'e') ^=qtr_dt) then do;
- s0 =qtr_dt; s =1;
- end;
- drop s0;
- run;
- data rate_all2nonRrr3;
- do _n_ =1 by 1 until(last.acct_ref_no);
- set rate_all2nonRrr2;
- by clnt_no acct_ref_no;
- i1 =sum(i1,1);
- if (^i2) then if (s =2) then do; /* fetch 1st record @ s =2*/
- i3 =s; i4 =i1; i2 =1;
- end;
- end;
- i5 =i1; /*number of records for that id */
- i6 =s ; /*s @ last record for that id */
- i1 =0 ;
- do _n_ =1 by 1 until(last.acct_ref_no);
- set rate_all2nonRrr2;
- by clnt_no acct_ref_no;
- i1 =sum(i1,1);
- if (i6 =3) then do;/*when s =3 (existing 3-consecutive records) then output the last 3 records*/
- if (i1 >i5 -3) then output;
- end;
- /*if no 3-consecutive records exist then output 1st 2-consecutive records, otherwise no output*/
- else if (i3 =2) then if (i1 >i4-2 & i1 <=i4) then output;
- end;
- drop s i1-i6;
- run;


雷达卡

京公网安备 11010802022788号







