proc sort data = orig ;
by x ;
run;
data temp (drop=y);
set orig ;
by x ;
length temp_z $20 ;
retain temp_z ;
if first.x then temp_z = '' ;
temp_z = catx(',',temp_z,y) ;
if last.x then output ;
run;
data new (drop=temp_z);
merge orig temp ;
by x ;
if not last.x then z=compress(tranwrd(temp_z,strip(y)||',','')) ;
else z=compress(tranwrd(temp_z,','||strip(y),'')) ;
run;