BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lynagh18
Fluorite | Level 6

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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.

PG

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
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;

 

PGStats
Opal | Level 21

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.

PG
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1039 views
  • 0 likes
  • 3 in conversation