Something like below should work.
data have;
row_id=_n_;
length row_id 8 term $2000;
row_id=1;
term='The length of this text is a very long text. As per CDISC standards, all variables in datasets should have a maximum length of 200 characters. As a consequence, this text needs to be split into variables TERM1, TERM2, ... TERMX, with each having 200 characters long.';
output;
row_id=2;
term=repeat('aaa bbb ',180);
output;
run;
data split_200(keep=row_id term_:);
length term_200 $200;
set have;
_pos_start=1;
_pos_stop =_pos_start+200;
do term_no=1 by 1;
_pos_found=findc(term,' ',-_pos_stop);
term_200 =substr(term,_pos_start,_pos_found-_pos_start);
if missing(term_200) then leave;
output;
_pos_start=_pos_found+1;
_pos_stop =_pos_start+200;
end;
run;
proc transpose data=split_200 out=split_200_transp(drop=_name_) prefix=term_;
by row_id;
id term_no;
var term_200;
run;
data want;
merge have split_200_transp;
by row_id;
run;
proc print data=want;
run;
@Maneesh27 Code in previous post just amended with a corrected expression for the substr() function.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: