<?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: How to replace a string starting with specific characters in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844645#M41722</link>
    <description>Thanks! I run the code, "blar abc" is replaced by "blar xxx", but "blar abc123" is replaced by "blar xxx123".&lt;BR /&gt;The output I would like is that "blar abc123" also being replaced by "blar xxx". Any string that starts with "abc" should be replaced by "xxx" while left the rest of the sentence in place.</description>
    <pubDate>Wed, 16 Nov 2022 15:56:39 GMT</pubDate>
    <dc:creator>EG_user</dc:creator>
    <dc:date>2022-11-16T15:56:39Z</dc:date>
    <item>
      <title>How to replace a string starting with specific characters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844626#M41716</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which contains text fields.&lt;/P&gt;&lt;P&gt;In the text field,&amp;nbsp; I would like to replace a part of the sentence like " ABC123" with "XXX".&lt;/P&gt;&lt;P&gt;The string always starts with ABC, but the numbers behind the characters varies.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So:&lt;/P&gt;&lt;P&gt;ABC123 -&amp;gt; XXX&lt;/P&gt;&lt;P&gt;ABC4567 -&amp;gt; XXX&lt;/P&gt;&lt;P&gt;ABC45B12-&amp;gt; XXX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried TRANWRD, but it only changes the ABC123 -&amp;gt; XXX123.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 14:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844626#M41716</guid>
      <dc:creator>EG_user</dc:creator>
      <dc:date>2022-11-16T14:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a string starting with specific characters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844630#M41717</link>
      <description>&lt;P&gt;Look at the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0r8h2fa8djqf1n1cnenrvm573br.htm" target="_self"&gt;PRXCHANGE Function&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Here's an example with your data, note it only replaces "abc" when followed by numbers:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
	infile cards ;
	input string $;
cards ;
abc
abc123
abc234
abc4567
bad123
;

data want ;
	retain 
		patternID ;
	set have ;
	if _n_=1 then do ;
		/* Create a Subsitute Regular Expression */
		/* (abc)(\d.) Searches for abc followed by 1 or more (.) digits (\d) */
	    /* xxx$2 what the found term is replaced with, the $2 is the contents 2nd search term (\d.) */
		patternID=prxparse('s/(abc)(\d.)/xxx$2/') ;
	end ;
	/* This actually does the substitution  */
	newString=prxchange(patternID,1,string) ;
	put string= newString= ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Nov 2022 15:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844630#M41717</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-11-16T15:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a string starting with specific characters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844632#M41718</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if string=:'ABC' then string='XXX';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note the colon after the equal sign, that indicates we are testing to see if the variable STRING &lt;EM&gt;begins with&lt;/EM&gt; 'ABC'&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 15:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844632#M41718</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-16T15:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a string starting with specific characters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844637#M41719</link>
      <description>Hi, thanks for reply.&lt;BR /&gt;Does it work in a sentence? So, my variable does not only contains 1 string like "ABC123", it is a whole text field&lt;BR /&gt;For example "Restaurant ABC123 has great hamburgers" , I would like te result to be "Restaurant XXX has great hamburgers".&lt;BR /&gt;Or "Yesterday I walked by restaurant ABC345, and it was closed" to be "Yesterday I walked by restaurant XXX, and it was closed".&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Nov 2022 15:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844637#M41719</guid>
      <dc:creator>EG_user</dc:creator>
      <dc:date>2022-11-16T15:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a string starting with specific characters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844638#M41720</link>
      <description>&lt;P&gt;Always best to describe the actual problem rather than a simplified problem where the answer someone gives doesn't apply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a sentence, you would have to test each word in sequence and then do the replacement if it finds 'ABC', so yes, it does work if you do it that way.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 15:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844638#M41720</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-16T15:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a string starting with specific characters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844640#M41721</link>
      <description>&lt;P&gt;Different example for sentances&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
	infile cards ;
	input string $30.;
cards ;
blar abc
blar abc123
blar abc234
blar abc4567
blar bad123
;

data want ;
	retain 
		patternID ;
	length newString $20 ;
	set have ;
	if _n_=1 then do ;
		/* Create a Subsitute Regular Expression */
		/* (abc)(\d.) Searches for abc followed by 1 or more (.) digits (\d) */
	    /* xxx$2 what the found term is replaced with, the $2 is the contents 2nd search term (\d.) */
		patternID=prxparse('s/abc/xxx/') ;
	end ;
	/* This actually does the substitution  */
	newString=prxchange(patternID,-1,string) ;
	put string= newString= ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Nov 2022 15:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844640#M41721</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-11-16T15:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a string starting with specific characters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844645#M41722</link>
      <description>Thanks! I run the code, "blar abc" is replaced by "blar xxx", but "blar abc123" is replaced by "blar xxx123".&lt;BR /&gt;The output I would like is that "blar abc123" also being replaced by "blar xxx". Any string that starts with "abc" should be replaced by "xxx" while left the rest of the sentence in place.</description>
      <pubDate>Wed, 16 Nov 2022 15:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844645#M41722</guid>
      <dc:creator>EG_user</dc:creator>
      <dc:date>2022-11-16T15:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a string starting with specific characters</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844651#M41723</link>
      <description>Thank you very much! I understand it now, so for more digits I can use "prxparse('s/(abc)(\d.)/xxx/')</description>
      <pubDate>Wed, 16 Nov 2022 16:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-replace-a-string-starting-with-specific-characters/m-p/844651#M41723</guid>
      <dc:creator>EG_user</dc:creator>
      <dc:date>2022-11-16T16:14:54Z</dc:date>
    </item>
  </channel>
</rss>

