In the future please describe how "it doesn't work", unexpected output and the expected result, no output or error messages.
With that, is this what you may have been looking for:
data work.ruta_1;
ruta = "O:\_Privada\JVidal\Proyecto base\proyecto base.egp";
nomfich=scan(ruta,-1,'\');
pos1 = indexw(ruta,strip(nomfich),'\.');
pos2 = indexw(ruta, 'proyecto','\ ');
run;
pos1 = indexw(ruta,strip(nomfich),'\.'); Needs to have blanks removed. If you look at the properties of the variable NOMFICH you will see that it is 200 characters long. The blanks at the end are included in comparisons unless removed for the operation. ALSO you need to provide information that \ is a word boundary character.