Emmmm.
It is much complicated.
Suppose your id variable is numeric.
[pre]
data test;
input id;
cards;
1
1
2
2
2
3
3
4
5
6
6
7
7
8
;
run;
ods output nlevels=level;
proc freq data=test nlevels ;
table id /out=id(keep=id) nopercent nofreq nocum ;
run;
data temp(keep=id flag);
set id;
if _n_ eq 1 then set level;
retain flag 0;
div=floor(nlevels/5);
if div eq 1 then do;
if mod(_n_,div) eq 0 and flag le 4 then flag+1;
end;
else do;
if mod(_n_,div) eq 1 and flag le 4 then flag+1;
end;
run;
data op;
set temp;
by flag;
length level $ 200;
retain level;
if first.flag then call missing(level);
level=catx(' ',level,id);
if last.flag then output;
run;
data _null_;
set op;
call symputx(cats('d',flag),level);
run;
data d1 d2 d3 d4 d5;
set test;
select;
when (id in (&d1)) output d1;
when (id in (&d2)) output d2;
when (id in (&d3)) output d3;
when (id in (&d4)) output d4;
when (id in (&d5)) output d5;
otherwise;
end;
run;
[/pre]
Ksharp
Message was edited by: Ksharp