try hash object, it might improve processing speed.
proc univariate noprint data=data1;
var vol;
output out=quintile pctlpts=10 20 80 90 pctlpre=pct;
by size;
run;
data data2;
attrib
pct10 length=8
pct20 length=8
pct80 length=8
pct90 length=8
group length=8;
if _n_=1 then do;
declare hash p(dataset: 'quintile(rename=(size=id))',ordered: 'yes');
declare hiter pi('p');
p.definekey('id');
p.definedata('id','pct10','pct20','pct80','pct90');
p.definedone();
call missing(id,vol,pct10,pct20,pct80,pct90,group);
end;
keep size dir date stk vol group;
set data1;
rc=pi.setcur(key: size);
do until(rc ne 0 or size ne id);
if rc=0 then do;
if .<vol<=pct10 then group=1;
if pct10<vol<=pct20 then group=2;
if pct20<vol<=pct80 then group=3;
if pct80<vol<=pct90 then group=4;
if pct90<vol then group=5;
end;
rc=pi.next();
end;
run;
|