Returns the last word in a \ delimited string i.e the program name for a full path

function laststr(instr $) $;
length outstr $2000;
outstr=reverse(scan(reverse(instr),1,'\'));
return (outstr);
endsub;

data _null_;
path= 's:\this\is\a\test\path\testprog.sas';
progname=laststr(path);
put 'program' progname;
run;

results in log program testprog.sas