<?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 Finding letters in string and amending them based on it in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-letters-in-string-and-amending-them-based-on-it/m-p/929157#M44813</link>
    <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a string variable called string and what I need to do is search for certain letters such as S or X and if I find it then I need to convert the string to XXXX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have some example code to do this?&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sean&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test;
infile datalines delimiter=',';
   input string $ newstring $;
   datalines;
F03  J47  S528 X590,F03  J47  XXXX XXXX
E872  R263 S720 X590,E872  XXXX XXXX XXXX
S720 X590,XXXX XXXX
S150 V789,XXXX V789
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 21 May 2024 14:08:14 GMT</pubDate>
    <dc:creator>Sean_OConnor</dc:creator>
    <dc:date>2024-05-21T14:08:14Z</dc:date>
    <item>
      <title>Finding letters in string and amending them based on it</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-letters-in-string-and-amending-them-based-on-it/m-p/929157#M44813</link>
      <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a string variable called string and what I need to do is search for certain letters such as S or X and if I find it then I need to convert the string to XXXX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have some example code to do this?&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sean&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test;
infile datalines delimiter=',';
   input string $ newstring $;
   datalines;
F03  J47  S528 X590,F03  J47  XXXX XXXX
E872  R263 S720 X590,E872  XXXX XXXX XXXX
S720 X590,XXXX XXXX
S150 V789,XXXX V789
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 May 2024 14:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-letters-in-string-and-amending-them-based-on-it/m-p/929157#M44813</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2024-05-21T14:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Finding letters in string and amending them based on it</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-letters-in-string-and-amending-them-based-on-it/m-p/929164#M44814</link>
      <description>&lt;P&gt;If you don't care if the words in the source string are separated by one or multiple blanks and you don't need to maintain this then use Option 1.&lt;/P&gt;
&lt;P&gt;If you need to maintain the number of separating blanks then consider Option 2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=',' dsd truncover;
   input string :$40. newstring :$40.;
   datalines;
F03  J47  S528 X590,F03  J47  XXXX XXXX
E872  R263 S720 X590,E872  XXXX XXXX XXXX
S720 X590,XXXX XXXX
S150 V789,XXXX V789
;
run;

data want(drop=_:);
  set have;
  /* option 1 */
  length newstring_2 $40 _term $10;
  do _i=1 to countw(string,' ');
    _term=scan(string,_i,' ');
    if findc(_term,'rsx','i') then _term='XXXX';
    newstring_2=catx(' ',newstring_2,_term);
  end;
  /* option 2 */
  length newstring_3 $40.;
  newstring_3=prxchange('s/\b[^ ]*[rsx][^ ]*\b/XXXX/i',-1,strip(newstring));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Based on your sample data I'm also converting words to XXXX that contain the letter R.&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 15:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-letters-in-string-and-amending-them-based-on-it/m-p/929164#M44814</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-21T15:16:16Z</dc:date>
    </item>
  </channel>
</rss>

