data ex_5; length parts $1000; set text; do i=1 to length(text)-200; parts=substr(text, i, 200); last_word=scan(parts, countw(parts)); k=lengthn(last_word); if find(text, last_word) then do; temp=200; end; else do; temp=200 - length(last_word); end; i+(temp-1); output; n+1; end; run; data final; set ex_5; len=length(parts) - length(last_word); if find(text, last_word) then parts1=parts; else parts1=substr(parts, 1, len); drop parts i len temp; run; proc transpose data=final out=final_final; id last_word; var parts1; run; I tried this code, but it has some issues, such as the find function not always working.
... View more