proc sql undo_policy=none;
create table a as
select a.*,b.value as value_1
from aaa as a
left join aaa(where=(index(VisitName,"_"))) as b
on a.SID=b.SID and a.XM=b.XM and a.VIsitName=scan(b.VisitName,1,'_')
;
quit;
data a;
set a;
if ^missing(value_1) then value=value_1 ;
drop value_1;
run;