<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to use a variable as input for a function such as prxchange (or whichever function that works) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538405#M148221</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code chunk below works, but instead of specifying 'W28' inside the &lt;EM&gt;prxchange&lt;/EM&gt; function, I want to list a variable because the value could be different for every row that this function is iterated over.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is something similar to the code chunk below where I replaced the value, 'W28' with the variable, ICD, inside the &lt;EM&gt;prxchange&lt;/EM&gt; function&amp;nbsp;but this syntax is not valid, obviously.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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;&lt;BR /&gt;length FinalICDs $11;
FinalICDs=prxchange('s/',ICD,'*//i',-1,MoreICDs);
run;&lt;/PRE&gt;&lt;P&gt;The output I want is:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;ICD&amp;nbsp; &amp;nbsp; MoreICDs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FinalICDs&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; W28&amp;nbsp; &amp;nbsp;W28 W75 X47&amp;nbsp; &amp;nbsp; &amp;nbsp;W75 X47&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; W75&amp;nbsp; &amp;nbsp;W28 W75 X47&amp;nbsp; &amp;nbsp;&amp;nbsp;W28&amp;nbsp; X47&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; C67&amp;nbsp; &amp;nbsp; W75 V86 X47&amp;nbsp; &amp;nbsp; &amp;nbsp;W75 V86 X47&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've researched for awhile now and hoping someone in this community can help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Feb 2019 19:51:23 GMT</pubDate>
    <dc:creator>lynagh18</dc:creator>
    <dc:date>2019-02-25T19:51:23Z</dc:date>
    <item>
      <title>How to use a variable as input for a function such as prxchange (or whichever function that works)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538405#M148221</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code chunk below works, but instead of specifying 'W28' inside the &lt;EM&gt;prxchange&lt;/EM&gt; function, I want to list a variable because the value could be different for every row that this function is iterated over.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is something similar to the code chunk below where I replaced the value, 'W28' with the variable, ICD, inside the &lt;EM&gt;prxchange&lt;/EM&gt; function&amp;nbsp;but this syntax is not valid, obviously.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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;&lt;BR /&gt;length FinalICDs $11;
FinalICDs=prxchange('s/',ICD,'*//i',-1,MoreICDs);
run;&lt;/PRE&gt;&lt;P&gt;The output I want is:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;ICD&amp;nbsp; &amp;nbsp; MoreICDs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FinalICDs&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; W28&amp;nbsp; &amp;nbsp;W28 W75 X47&amp;nbsp; &amp;nbsp; &amp;nbsp;W75 X47&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; W75&amp;nbsp; &amp;nbsp;W28 W75 X47&amp;nbsp; &amp;nbsp;&amp;nbsp;W28&amp;nbsp; X47&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; C67&amp;nbsp; &amp;nbsp; W75 V86 X47&amp;nbsp; &amp;nbsp; &amp;nbsp;W75 V86 X47&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've researched for awhile now and hoping someone in this community can help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 19:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538405#M148221</guid>
      <dc:creator>lynagh18</dc:creator>
      <dc:date>2019-02-25T19:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a variable as input for a function such as prxchange (or whichever function that work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538410#M148225</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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&amp;gt;0 then substr(MoreICDs,k,3)=' ';
MoreICDs=compbl(MoreICDs);
drop k;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*Or  keeping both Moreicds and the new want variable*/
data want;
set temp;
k=findw(MoreICDs,strip(icd));
want=MoreICDs;
if k&amp;gt;0 then substr(want,k,3)=' ';
want=compbl(want);
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 20:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538410#M148225</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-25T20:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a variable as input for a function such as prxchange (or whichever function that work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538430#M148231</link>
      <description>&lt;P&gt;This would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp2;
set temp;
length FinalICDs $11;
FinalICDs=left(compbl(tranwrd(moreICDs, ICD, "")));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and be more efficient, I guess, than an uncompiled prx pattern.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 20:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538430#M148231</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-25T20:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a variable as input for a function such as prxchange (or whichever function that work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538625#M148290</link>
      <description>This is great! Thanks so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 26 Feb 2019 13:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-variable-as-input-for-a-function-such-as-prxchange/m-p/538625#M148290</guid>
      <dc:creator>lynagh18</dc:creator>
      <dc:date>2019-02-26T13:34:31Z</dc:date>
    </item>
  </channel>
</rss>

