In MUMPS you don't need sort function because array subscripts are being automatically sorted.
So the easiest way is to create another array with sort dimension being first piece of data and value - second piece of data:
for i=1:1:Arr(0) set piece1=$piece(Arr(i),"^",1), piece2=$piece(Arr(i),"^",2), Temp(piece1)=$get(Temp(piece1))_piece2_","
after running that code you will get following array
Temp("ATC")="1,3,"
Temp("BTC")="2,5,"
Temp("CTC")="4,"
Then you traverse that array and build one you need:
set i="",Brr=0 for set i=$o(Temp(i)) quit:i="" set Brr=Brr+1,Brr(Brr)=i_":"_Temp(i)
You will get an array you need:
Brr(1)="ATC:1,3,"
Brr(2)="BTC:2,5,"
Brr(3)="CTC:4,"