<?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 Re: Replace string with another string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475979#M122451</link>
    <description>&lt;P&gt;One case that is missing from your example:&amp;nbsp; Sri&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should that become Srx or should it become Srxx?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At any rate, here are the basic tools that you can modify if needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if length(var2) &amp;gt; 2 then substr(var2, 3, 2) = 'xx';&lt;/P&gt;</description>
    <pubDate>Fri, 06 Jul 2018 13:09:26 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-07-06T13:09:26Z</dc:date>
    <item>
      <title>Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475975#M122449</link>
      <description>&lt;P&gt;data ds;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input var1 var2$10.;&lt;BR /&gt;datalines;&lt;BR /&gt;201 Pakistan&lt;BR /&gt;206 Bangladesh&lt;BR /&gt;209 Russia&lt;BR /&gt;208 China&lt;/P&gt;&lt;P&gt;245&amp;nbsp;In&lt;/P&gt;&lt;P&gt;862 L&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;what i need is&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Paxxstan&lt;BR /&gt;baxxladesh&lt;BR /&gt;Ruxxia&lt;/P&gt;&lt;P&gt;chxxa&lt;/P&gt;&lt;P&gt;In&lt;BR /&gt;L&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 12:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475975#M122449</guid>
      <dc:creator>srinath3111</dc:creator>
      <dc:date>2018-07-06T12:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475978#M122450</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    substr(country,3,1)='x';
    substr(country,4,1)='x';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 13:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475978#M122450</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-06T13:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475979#M122451</link>
      <description>&lt;P&gt;One case that is missing from your example:&amp;nbsp; Sri&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should that become Srx or should it become Srxx?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At any rate, here are the basic tools that you can modify if needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if length(var2) &amp;gt; 2 then substr(var2, 3, 2) = 'xx';&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 13:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475979#M122451</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-06T13:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475983#M122454</link>
      <description>&lt;BR /&gt;data want;&lt;BR /&gt;set ds;&lt;BR /&gt;if length(var2) &amp;gt;2 then&lt;BR /&gt;var3 = tranwrd(var2,substr(var2,3,2),"XX");&lt;BR /&gt;else var3 = var2;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Jul 2018 13:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/475983#M122454</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-07-06T13:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string with another string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/476017#M122464</link>
      <description>&lt;P&gt;You can use substr() function along with IF condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set ds;
if length(var2)&amp;lt;=2 then new_var=var2;
else if length(var2)=3 then new_var=substr(var2,1,2)||"x"||substr(var2,5);
else new_var=substr(var2,1,2)||"xx"||substr(var2,5);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another alternate solution will be using the Perl expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set ds;
new_var=substr(var2,1,2)||prxchange('s/[a-z][a-z]/xx/i',1,substr(var2,3));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 14:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-string-with-another-string/m-p/476017#M122464</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-07-06T14:29:28Z</dc:date>
    </item>
  </channel>
</rss>

