<?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 Subtitute with pearl function in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190117#M47986</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can &lt;STRONG&gt;prxchange &lt;/STRONG&gt;function ne used to substitute variable &lt;STRONG&gt;a &lt;/STRONG&gt; in table &lt;STRONG&gt;have&lt;/STRONG&gt; A with 1 , B with 2, C with 3, D with 4.&lt;/P&gt;&lt;P&gt;I have been only able to group ([ABCD]) the searched characters , but not able to determine the substitute pattern as described above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know I can do it by using transtrn function but I am interested in using pearl functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;a='2A345';output;&lt;BR /&gt;a='2B134';output;&lt;BR /&gt;a='3C124';output;&lt;BR /&gt;a='4D123';output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;b=prxchange('s/[ABCD]/1234/i',1,a);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;10x&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Jan 2015 12:18:42 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2015-01-20T12:18:42Z</dc:date>
    <item>
      <title>Subtitute with pearl function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190117#M47986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can &lt;STRONG&gt;prxchange &lt;/STRONG&gt;function ne used to substitute variable &lt;STRONG&gt;a &lt;/STRONG&gt; in table &lt;STRONG&gt;have&lt;/STRONG&gt; A with 1 , B with 2, C with 3, D with 4.&lt;/P&gt;&lt;P&gt;I have been only able to group ([ABCD]) the searched characters , but not able to determine the substitute pattern as described above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know I can do it by using transtrn function but I am interested in using pearl functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;a='2A345';output;&lt;BR /&gt;a='2B134';output;&lt;BR /&gt;a='3C124';output;&lt;BR /&gt;a='4D123';output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;b=prxchange('s/[ABCD]/1234/i',1,a);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;10x&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jan 2015 12:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190117#M47986</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2015-01-20T12:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Subtitute with pearl function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190118#M47987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No. You can't do that with prxchange() .use translate() instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
a='2A345';output;
a='2B134';output;
a='3C124';output;
a='4D123';output;
run;
data want;
set have;
b=translate(a,'1234','ABCD');
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jan 2015 12:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190118#M47987</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-01-20T12:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: Subtitute with pearl function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190119#M47988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ok, 10x.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jan 2015 15:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190119#M47988</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2015-01-20T15:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Subtitute with pearl function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190120#M47989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you really wanted to accomplish this with regular expressions (say your real data is much more complex than this data) then an approach to use could be similar to the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;a='2A345';output;&lt;/P&gt;&lt;P&gt;a='2B134';output;&lt;/P&gt;&lt;P&gt;a='3C124';output;&lt;/P&gt;&lt;P&gt;a='4D123';output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;array r[4] $1 _temporary_ ('1' '2' '3' '4');&lt;/P&gt;&lt;P&gt;prxid = prxparse('/(A)|(B)|(C)|(D)/io');&lt;/P&gt;&lt;P&gt;do until(done);&lt;/P&gt;&lt;P&gt;set have end=done;&lt;/P&gt;&lt;P&gt;pos = prxmatch(prxid, a);&lt;/P&gt;&lt;P&gt;if pos then do;&lt;/P&gt;&lt;P&gt;idx = prxparen(prxid);&lt;/P&gt;&lt;P&gt;substr(a, pos, 1) = r[idx];&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jan 2015 16:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190120#M47989</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2015-01-20T16:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: Subtitute with pearl function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190121#M47990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And, if you only need to change the 2nd character and its always an uppercase letter, then you could use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; substr(a,2,1)=rank(substr(a,2,1))-64;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jan 2015 16:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subtitute-with-pearl-function/m-p/190121#M47990</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-01-20T16:55:19Z</dc:date>
    </item>
  </channel>
</rss>

