I would never recommend actually using this approach as it is far overly complicated, fairly inflexible and the worst performing of all the suggestions:
proc fcmp outlib=work.func.excl;
function vlookup(dsname $, idvar $, id, col_index) $ 200;
length val $ 200;
dsn=cats(dsname, '(where=(', idvar, '=', id, '))');
dsid=open(dsn);
if dsid=0 then do;
put '4552524f523a20'x 'No lookup value for ' id=;
return ('');
end;
vartype=vartype(dsid, col_index);
rc=fetch(dsid);
if rc ne 0 then do;
msg=sysmsg();
put msg;
return ('');
end;
if vartype='C' then do;
val=getvarc(dsid, col_index);
end;
else do;
varfmt=varfmt(dsid, col_index);
val=putn(getvarn(dsid, col_index), varfmt);
end;
rc=close(dsid);
return (val);
endsub;
run;
options cmplib=work.func;
data have;
input id name $14. report_to;
cards;
200000 Andrew, Skype 000006
520001 Walker, Walker 000006
200000 Andrew, Skype 000006
520001 Walker, Walker 000006
000006 Smith, John 000007
000007 Phil, Elias 000010
000008 Turner, Sandra 200000
000010 Santa, Clause 200000
;
data want;
set have;
report_to_name=vlookup('have', 'id', report_to, 2);
run;
obs | id | name | report_to | reports_to_name |
200000 | Andrew, Skype | 6 | Smith, John |
520001 | Walker, Walker | 6 | Smith, John |
200000 | Andrew, Skype | 6 | Smith, John |
520001 | Walker, Walker | 6 | Smith, John |
6 | Smith, John | 7 | Phil, Elias |
7 | Phil, Elias | 10 | Santa, Clause |
8 | Turner, Sandra | 200000 | Andrew, Skype |
10 | Santa, Clause | 200000 | Andrew, Skype |