If there was only one ID variables, That would be more simple.
data have;
infile cards truncover expandtabs;
input ID $ a1 s2 d3 f4 g5;
cards;
a1 0 2.56217 3.36783 3.53842 3.00214
s2 2.56217 0 2.87413 4.1333 3.60389
d3 3.36783 2.87413 0 2.46764 3.39893
f4 3.53842 4.1333 2.46764 0 2.97952
g5 3 3 3.39893 2.97952 0
;
run;
%let dsid=%sysfunc(open(have));
%let nvars=%sysfunc(attrn(&dsid,nvars));
%let dsid=%sysfunc(close(&dsid));
data want;
set have;
array have{*} _numeric_;
array id_{%eval(&nvars-1)} $ 32;
do i=1 to dim(have);
min=min(of have{*});
idx=whichn(min,of have{*});
id_{i}=vname(have{idx});
have{idx}=.;
end;
keep id id_: ;
run;