By adding some Hash to Xia Keshan's code should fit your bill: data have; input Application_id Reaon_code : $20. Value $; cards; 123 AB31AB45AB45 £500 124 AB43RD49TY87 £640 125 RT87RT87 £900 126 CD19RV29CD19 £1000 ; run; data want; set have; do i=1 to length(Reaon_code) by 4; if i=1 then do; declare hash h1(ordered:'a'); h1.definekey('i'); h1.definedata('code','waterfall_reason'); h1.definedone(); declare hash h2(); h2.definekey('code'); h2.definedone(); declare hiter hi('h1'); end; Waterfall_reason=ifn(i=1,1,0); code=substr(Reaon_code,i,4); if h2.check() ne 0 then do; rc=h2.replace(); rc=h1.replace(); end; end; unique_reason=ifn(h1.num_items=1,1,0); do rc=hi.first() by 0 while (rc=0); output; rc=hi.next(); end; drop i rc; run;
... View more