this code takes a character string of words and just gets the last 3 words. I purposely made the length of the words different. Don't know if this is the kind of thing you wanted to do.
*****************************************
data temp;
wordstring = 'abc defg hijkl m nop qrstuvw xyz';
end1 = length(wordstring);
array start{*} start1-start3;
array end{*} end1-end3;
array lngth{*} lngth1-lngth3;
start1 = anyspace(wordstring,-end1) + 1;
lngth1 = end1 - start1 + 1;
word1 = substr(wordstring,start1,lngth1);
do i = 2 to 3;
start{i} = anyspace(wordstring,-(start{i-1}-2)) + 1;
lngth{i} = start{i-1} - start{i} -1;
end;
word2 = substr(wordstring,start2,lngth2);
word3 = substr(wordstring,start3,lngth3);
run;
proc print data = temp;
var wordstring word1-word3; run;