It think the best way would be to perform the final cleaning in a second step.
But depending on
how much data cleaning you need to finally get TEXT1 and TEXT2
wether you want to check the conformity of the syntax or not
your facility to re-understand, debug or refine regex you wrote a time ago
you may want to come up with a solution like this:
data want;
set have;
length Reason ReasonSp $200;
*Roughly extract TEXT1 and TEXT2;
Reason = strip(substrn(scan(value,1,':,'),find(Value,' ')));
ReasonSp = scan(value,2,':,');
*Data cleaning;
array checkNClean Reason ReasonSp;
do over checkNClean;
*Remove trailing dot;
if substrn(reverse(strip(checkNClean)),1,1) eq '.' then checkNClean=reverse(substrn(reverse(strip(checkNClean)),2));
*Remove leading i.e.;
if substrn(strip(checkNClean),1,4) eq 'i.e.' then checkNClean=strip(substrn(strip(checkNClean),5));
end;
run;
proc print;run;
... View more