Hi all,
My aim is to remove a specific set of characters from a string. I want to specify the set of characters to be removed by using a variable, instead of explicitly writing the characters in the prx function.
The code chunk below works, but instead of specifying 'W28' inside the prxchange function, I want to list a variable because the value could be different for every row that this function is iterated over.
data temp;
input id 1 ICD $ 3-5 MoreICDs $ 7-17;
datalines;
1 W28 W75 V86 X47
2 W75 W28 W75 X47
3 C67 W75 V86 X47
;
run;
data temp2;
set temp;
string1=prxchange('s/W28*//i',-1,MoreICDs);
*put string1=;
run;
What I want is something similar to the code chunk below where I replaced the value, 'W28' with the variable, ICD, inside the prxchange function but this syntax is not valid, obviously.
data temp; input id 1 ICD $ 3-5 MoreICDs $ 7-17; datalines; 1 W28 W75 V86 X47 2 W75 W28 W75 X47 3 C67 W75 V86 X47 ; run; data temp2; set temp;
length FinalICDs $11; FinalICDs=prxchange('s/',ICD,'*//i',-1,MoreICDs); run;
The output I want is:
ID ICD MoreICDs FinalICDs
1 W28 W28 W75 X47 W75 X47
2 W75 W28 W75 X47 W28 X47
3 C67 W75 V86 X47 W75 V86 X47
I've researched for awhile now and hoping someone in this community can help.
Thanks!
John
This would work:
data temp2;
set temp;
length FinalICDs $11;
FinalICDs=left(compbl(tranwrd(moreICDs, ICD, "")));
run;
and be more efficient, I guess, than an uncompiled prx pattern.
data temp;
input id 1 ICD $ MoreICDs $ 7-17;
datalines;
1 W28 W28 W75 X47
2 W75 W28 W75 X47
3 C67 W75 V86 X47
;
run;
data want;
set temp;
k=findw(MoreICDs,strip(icd));
if k>0 then substr(MoreICDs,k,3)=' ';
MoreICDs=compbl(MoreICDs);
drop k;
run;
/*Or keeping both Moreicds and the new want variable*/
data want;
set temp;
k=findw(MoreICDs,strip(icd));
want=MoreICDs;
if k>0 then substr(want,k,3)=' ';
want=compbl(want);
drop k;
run;
This would work:
data temp2;
set temp;
length FinalICDs $11;
FinalICDs=left(compbl(tranwrd(moreICDs, ICD, "")));
run;
and be more efficient, I guess, than an uncompiled prx pattern.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.