You could use a regular expression as shown below. data have; string="Hi i want to split a sentence into variables with same length, but i dont want the words to be truncated in the new variable,if it is going to be truncated then it must move on to the next variable.For eg: If i have sentence of length"; output; string="For eg: If i have sentence of length 200 bytes, i want to split the sentence into 4 variables each of 50 bytes and they should not have truncated words.I have done a complex macro to do this but i am looking for a much simpler method"; output; run; data prep /*(drop=_:)*/; length sub_string $50; retain _re; length _start _stop _pos _len 8; if _N_ = 1 then _re = prxparse('/(?<=\b)[\w].{0,48}([^\w]|$)/'); set have; _start=1; _stop = lengthn(string); do until (_start>_stop); call prxnext(_re, _start, _stop, string, _pos, _len); sub_string = substrn(string, _pos, _len); output; if missing(sub_string) then leave; end; run; proc transpose data=prep out=want(drop=_:) prefix=var; by string notsorted; var sub_string; run;
... View more