Pre-process the string and add your split character, then datastep split the string out: %macro Chop (inds=,invar=,num_output_cols=,max_length=40); data &inds. (drop=text_to_process); set &inds.; attrib &invar._new_text format=$2000.; attrib text_to_process format=$2000.; text_to_process=&invar.; do while (length(trim(text_to_process)) > &max_length.); &invar._new_text=trim(&invar._new_text)||'$'||substr(text_to_process,1,prxmatch("/\/[^\/]*$/",substr(tranwrd(text_to_process,' ','/'),1,40))); text_to_process=substr(text_to_process,prxmatch("/\/[^\/]*$/",substr(tranwrd(text_to_process,' ','/'),1,40))); end; &invar._new_text=trim(&invar._new_text)||'$'||trim(text_to_process); run; data &inds.; set &inds.; attrib %do i=1 %to &num_output_cols.; split_&i. %end; format=$&max_length..; %do i=1 %to &num_output_cols.; split_&i.=scan(&invar._new_text,&i.+1,"$"); %end; run; %mend Chop; data my_test; attrib really_long_string format=$200.; really_long_string="This is a long sentance which will be trimmed at this word as it splits over the row and also at this record as that splits as well."; output; run; %Chop (inds=work.my_test,num_output_cols=4,invar=really_long_string);
... View more