The T modifier removes the spaces. Add the space back into the delimiter list by using the S modifier.
s or S
adds space characters (blank, horizontal tab, vertical tab, carriage return, line feed, and form feed) to the list of characters.
t or T
trims trailing blanks from the string, word, and character arguments.
Try this:
data _null_;
length element $8;
element = 'BE';
found_at = findw('H He Li Be B C N O F Ne',element,' ','sit');
put found_at= ;
found_at = findw('H He Li Be B C N O F Ne',element,' ',1,'sit');
put found_at= ;
delims = ' ' ;
found_at = findw('H He Li Be B C N O F Ne',element,delims,'sit');
put found_at= ;
delims = ' ' ;
found_at = findw('H He Li Be B C N O F Ne',element,1,delims,'sit');
put found_at= ;
found_at = findw('H He Li Be B C N O F Ne',trim(element),' ','sit');
put found_at= 'explicit trim I and T modifiers' ;
found_at = findw('H He Li Be B C N O F Ne',trim(element),' ','si');
put found_at= 'explicit trim only I modifier';
found_at = findw('Be H He Li B C N O F Ne',trim(element),' ','sit');
put found_at= 'explicit trim I and T modifiers, Be first position' ;
run;
Result
found_at=9
found_at=9
found_at=9
found_at=9
found_at=9 explicit trim I and T modifiers
found_at=9 explicit trim only I modifier
found_at=1 explicit trim I and T modifiers, Be first position
... View more