<?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: Find and replace a substring in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401341#M97367</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169481"&gt;@Stefy67&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Below one way to go. The approach works only for single byte character sets and requires one of the more recent SAS versions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data due;
  nomenew2 = 'À à ÁÂÃÄÅ ÆAAAA è';
  cognomenew2 = 'ÔTTINA ÀÁÂÃÄÅÆAAAA';
run;

proc format;
   invalue $norm_to_A (default=256) 's/[ÀÁÂÃÄÅÆäà]/A/'   (regexpe) = _same_ other=_same_;
   invalue $norm_to_O (default=256) 's/[Ô]/O/'             (regexpe) = _same_ other=_same_;
   invalue $norm_to_E (default=256) 's/[è]/E/'             (regexpe) = _same_ other=_same_;
run;

data tre;
  set due;
  array c_vars {*} nomenew2 cognomenew2;
  do _i=1 to dim(c_vars);
    do _infmt='$norm_to_A','$norm_to_O','$norm_to_E';
  	 c_vars[_i]=inputc(c_vars[_i],_infmt);
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Oct 2017 14:21:50 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-10-05T14:21:50Z</dc:date>
    <item>
      <title>Find and replace a substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/400987#M97225</link>
      <description>&lt;P&gt;I have this problem: some values in VAR1 (see example) have special characters (&amp;nbsp;À &amp;nbsp;&amp;nbsp;Á &amp;nbsp;&amp;nbsp;Â &amp;nbsp;&amp;nbsp;Ã &amp;nbsp;&amp;nbsp;Ä&amp;nbsp; &amp;nbsp;). I want to find these special characters in a string and replace it with the correct letter (A) as showed in VAR2 of the example.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Var1&lt;/TD&gt;&lt;TD&gt;Var2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;SIAHMED&lt;/TD&gt;&lt;TD&gt;SIAHMED&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DANDREÁ&lt;/TD&gt;&lt;TD&gt;DANDREA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PELLIÇANO&lt;/TD&gt;&lt;TD&gt;PELLICANO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MATÃ&lt;/TD&gt;&lt;TD&gt;MATA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DONZELLA&lt;/TD&gt;&lt;TD&gt;DONZELLA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;DAGOSTINO&lt;/TD&gt;&lt;TD&gt;DAGOSTINO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ÔTTINA&lt;/TD&gt;&lt;TD&gt;OTTINA&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this instruction&lt;/P&gt;&lt;P&gt;var2 = TRANWRD (var1, "Á ", "A");&amp;nbsp; and it works but if I include more than one target it doesn't&lt;/P&gt;&lt;P&gt;var2 = TRANWRD (var1, "Á" or "Ã", "A");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Waiting for your suggestion&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 14:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/400987#M97225</guid>
      <dc:creator>Stefy67</dc:creator>
      <dc:date>2017-10-04T14:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace a substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/400993#M97227</link>
      <description>&lt;P&gt;You would do better to switch from TRANWRD to TRANSLATE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.2&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p05ww22zp7lcg3n1bjk7v93tscyo.htm&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.2&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p05ww22zp7lcg3n1bjk7v93tscyo.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That does exactly what you are asking for.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 14:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/400993#M97227</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-04T14:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace a substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401000#M97230</link>
      <description>&lt;P&gt;Check out the TRANSLATE function, which expression like the below, which converts all vowels to X.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name=translate(name,'XXXXX','AEIOU');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So presumably you could use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var2=translate(var1,'AAAAA','ÀÁÂÃÄ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just be sure that the second argument has as many iterations of the common value ('A') as there are characters in the 3rd argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 14:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401000#M97230</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-04T14:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace a substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401204#M97315</link>
      <description>&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 07:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401204#M97315</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-05T07:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace a substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401246#M97333</link>
      <description>Referring to my previous question, I write two lines together as below but the instruction doesn’t work.&lt;BR /&gt;Do I have to split for different dataset one instruction at a time?&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;Stefy67&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data tre;&lt;BR /&gt;set due;&lt;BR /&gt;nomenew3 = translate(nomenew2,'AAAAAAAAAAA','ÀÁÂÃÄÅÆĀĂĄǍ');&lt;BR /&gt;cognomenew3 = translate(cognomenew2,'AAAAAAAAAAA','ÀÁÂÃÄÅÆĀĂĄǍ');&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Oct 2017 09:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401246#M97333</guid>
      <dc:creator>Stefy67</dc:creator>
      <dc:date>2017-10-05T09:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace a substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401341#M97367</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169481"&gt;@Stefy67&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Below one way to go. The approach works only for single byte character sets and requires one of the more recent SAS versions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data due;
  nomenew2 = 'À à ÁÂÃÄÅ ÆAAAA è';
  cognomenew2 = 'ÔTTINA ÀÁÂÃÄÅÆAAAA';
run;

proc format;
   invalue $norm_to_A (default=256) 's/[ÀÁÂÃÄÅÆäà]/A/'   (regexpe) = _same_ other=_same_;
   invalue $norm_to_O (default=256) 's/[Ô]/O/'             (regexpe) = _same_ other=_same_;
   invalue $norm_to_E (default=256) 's/[è]/E/'             (regexpe) = _same_ other=_same_;
run;

data tre;
  set due;
  array c_vars {*} nomenew2 cognomenew2;
  do _i=1 to dim(c_vars);
    do _infmt='$norm_to_A','$norm_to_O','$norm_to_E';
  	 c_vars[_i]=inputc(c_vars[_i],_infmt);
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Oct 2017 14:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401341#M97367</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-05T14:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace a substring</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401345#M97370</link>
      <description>Thanks Patrick&lt;BR /&gt;&lt;BR /&gt;I solved the problem with your suggestions.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Oct 2017 14:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-and-replace-a-substring/m-p/401345#M97370</guid>
      <dc:creator>Stefy67</dc:creator>
      <dc:date>2017-10-05T14:11:35Z</dc:date>
    </item>
  </channel>
</rss>

