proc freq;
tables i*j/all sparse out=data1;
weight f;
run;
proc sort data=data1;
by i;
run;
data data2;
retain j1-j5;
array x(0:4) j1-j5;/*assume j has 5 levels*/
set data1;
by i;
x(mod((_n_-1),5))=count;
if not(last.i) then delete;
drop j count percent;
run;