<?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 characters in a string that follow certain characters? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647254#M193682</link>
    <description>&lt;P&gt;Is it always USD? Or are there other currencies?&lt;/P&gt;</description>
    <pubDate>Tue, 12 May 2020 21:47:35 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-05-12T21:47:35Z</dc:date>
    <item>
      <title>How to replace characters in a string that follow certain characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647240#M193673</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with long text fields. I need to replace every instance of a dollar amount, say, "439.33" with "439.33USD"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a sample data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
infile cards  ;
length name $200;
input name;
cards;
Ccy="USD"&amp;gt;738.56&amp;lt;/NS!figlwijfoaiu345Ccy="USD"&amp;gt;38.44&amp;lt;/ScT@
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So what I have is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ginak_3-1589317167406.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39355i651549F2E47DF1F6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ginak_3-1589317167406.png" alt="ginak_3-1589317167406.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want is &lt;EM&gt;USD&lt;/EM&gt; to be present after every dollar amount as is here:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ginak_1-1589316860096.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39353i9EEB89EC22313C12/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ginak_1-1589316860096.png" alt="ginak_1-1589316860096.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found two different community forums, and know that I will need a combination of&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;index
&lt;OL&gt;
&lt;LI&gt;To find the decimal point that follows any&lt;EM&gt; "USD"&lt;/EM&gt; in the text&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;substr&lt;/LI&gt;
&lt;LI&gt;tranwrd functions
&lt;OL&gt;
&lt;LI&gt;To replace that dollar amount with&lt;EM&gt; [dollaramount]USD&lt;/EM&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;There could be multiple instances of&lt;EM&gt; Ccy="USD"&amp;gt;[dollar amount]&lt;/EM&gt; in the string. I just want to tack on the USD after the dollar amount, but not every dollar amount is XYZ.AB, some are YZ.AB, some are Z.AB etc. There will always be a decimal point with two decimal places though that follow the &lt;EM&gt;Ccy="USD"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 21:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647240#M193673</guid>
      <dc:creator>ginak</dc:creator>
      <dc:date>2020-05-12T21:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace characters in a string that follow certain characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647254#M193682</link>
      <description>&lt;P&gt;Is it always USD? Or are there other currencies?&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 21:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647254#M193682</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-12T21:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace characters in a string that follow certain characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647259#M193684</link>
      <description>&lt;P&gt;This replaces:&lt;/P&gt;
&lt;P&gt;at least a digit followed by a dot followed by 2 digits&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;P&gt;the group found followed by USD.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TWO;
 set ONE; 
 NAME2=prxchange('s/(\d+\.\d\d)/\1USD/',-1,NAME);
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;{edited to avoid losing one character}&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 23:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647259#M193684</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-12T23:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace characters in a string that follow certain characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647260#M193685</link>
      <description>Hi there, yes it'll always say "USD" (and include the double quotes in the text too). Thanks!</description>
      <pubDate>Tue, 12 May 2020 22:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647260#M193685</guid>
      <dc:creator>ginak</dc:creator>
      <dc:date>2020-05-12T22:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace characters in a string that follow certain characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647264#M193688</link>
      <description>I think this works, thank you! It works with my fake sample data but I'll try it with my actual data tomorrow and let you know if I have any questions &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I never understood the prxchange command and where it comes from. Would love to learn more since it seems so useful</description>
      <pubDate>Tue, 12 May 2020 22:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647264#M193688</guid>
      <dc:creator>ginak</dc:creator>
      <dc:date>2020-05-12T22:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace characters in a string that follow certain characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647266#M193689</link>
      <description>&lt;P&gt;The syntax is that of Perl regular expressions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tons of tutorials on the web, that's how I learnt.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 23:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647266#M193689</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-12T23:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace characters in a string that follow certain characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647364#M193734</link>
      <description>&lt;P&gt;The solution presented by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;goes part of the way, but I would add a bit to make sure that only the right numbers get selected:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name=prxchange('s/("USD"&amp;gt;\d+\.\d\d)(?=&amp;lt;)/\1USD/',-1,name);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This looks for the string "USD"&amp;gt; followed by at least one digit, a period and two digits (that's the stuff in the first paranthesis). The whole thing should be followed by "&amp;lt;", but that string is not included in the match (the second paranthesis, "?=" denotes a look-ahead buffer), the match is replaced with the same plus the text "USD".&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 08:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-characters-in-a-string-that-follow-certain/m-p/647364#M193734</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-05-13T08:38:45Z</dc:date>
    </item>
  </channel>
</rss>

