if you values are pretty fixed here is the another approach. In first step where we use prxchange what we do is
we pick the pattern and extract what we want
for example for variable person number as shown below code snippet
PERSONnumber =prxchange('s/.+?PERSONnumber(.+?)''.+/$1/i', -1, str);
for example for variable person number as code shown above
(.+?) is the value we capture and contains anything after personnumber and before first single quote.
This captured value is $1 and replaces everything else. Same approach for every other variable. In the next step + is not replaced, when you have only +, otherwise + is removed. Hope I am clear in my explanation
data test ;
str=
"NAD+PERSONnumber+3456789010'DTM+091:170126:101'NAD+ENTITY+027'NAD+KLA+11'
NAD+YNR+'NAD+MOK+405'TAF+55:45:53:52:51:61:62:63:64:65:85:84:83:82:81:71:72:73:74:75'
TOB+85:OKK:0'TOB+75:OKK:0'TOB+63:MES:4'QTY+DYB:X'"
;
data test2(drop =str);
set test;
PERSONnumber =prxchange('s/.+?PERSONnumber(.+?)''.+/$1/i', -1, str);
DTM =prxchange('s/.+?DTM(.+?)''.+/$1/i', -1, str);
ENTITY=prxchange('s/.+?ENTITY(.+?)''.+/$1/i', -1, str);
KLA=prxchange('s/.+?KLA(.+?)''.+/$1/i', -1, str);
YNR=prxchange('s/.+?YNR(.+?)''.+/$1/i', -1, str);
MOK=prxchange('s/.+?MOK(.+?)''.+/$1/i', -1, str);
TAF=prxchange('s/.+?TAF(.+?)''.+/$1/i', -1, str);
TOB85=prxchange('s/.+?TOB\+85\:(.+?)''.+/$1/i', -1, str);
TOB75=prxchange('s/.+?TOB\+75\:(.+?)''.+/$1/i', -1, str);
TOB63=prxchange('s/.+?TOB\+63\:(.+)/$1/i', -1, str);
run;
data test3;
set test2;
array vars{*} _character_;
do i=1 to dim(vars);
if vars{i} = '+' then vars{i} = vars{i};
else vars{i} = substr(vars{i},2);
end;
run;
... View more