Now, I may get the point. Try again, please.
proc sort data = sashelp.class out = temp01;
by age;
run;
data _null_;
format age_list $100.;
if _n_ = 1 then do;
dcl hash h();
h.definekey("sex");
h.definedata("sex","age_list");
h.definedone();
end;
set temp01 end=eof;
if h.find()=0 then do;
if find(age_list,compress(age)) = 0 then do;
age_list = compress(age_list||","||age);
h.replace();
end;
end;else do;
age_list = age;
h.add();
end;
if eof then h.output(dataset:"temp02");
run;