Hi @mitchell_keener ,
It is easy to find the length of the new string (newL) you want to have. It is equal to
newL = length(text)-end1+length(type1)-end2+length(type2);
Then you can have a new_text with the length of newL to do the concatenation in steps as:
[1] new_text = 'My name is', type1;
[2] new_text = new_text, 'and my birthday is';
[3] new_text = new_text, type2;
You can modify your program using this logic. Actually you can combine the 3 statements as one.
Here is one simple way for you. This assumes that TEXT ends with the last string beginning with END2 (35).
data want;
set example;
array type type:;
array begin begin:;
array end end:;
length new_text $ &newL;
call catx(' ', new_text, substr(text,1,begin1-2),type1);
call catx(' ', new_text, substr(text, begin1+end1, begin2-1-begin1-end1));
call catx(' ', new_text, type2);
keep new_text;
run;
Edited:
The newL can be obtained as part of your Input Data Set which is shown under:
data example;
infile datalines truncover dlm=',';
input text $40. begin1 begin2 end1 end2 type1 $5. type2 $5.;
newL = length(text)-end1+length(type1)-end2+length(type2);
if _N_ = 1 then call symputx('newL', newL);
datalines;
My name is Kim and my birthday is 6/5/90,12,35,3,6,Name Date
;
run;
... View more