<?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 Replace last word with another word in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-last-word-with-another-word/m-p/722026#M223835</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp; have the following dataset and want to replace the last word if it is 'MD' or 'M.D.' or 'MD.' with 'MD'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;DATA EXAMPLE1;
  INPUT Names $char30.;
DATALINES;
AARON RAY, M.D.
AARON,RAY MD.
RAY,AARON,M.D.
PMD RAY ARON M.D
AARON MD RAY 
AARON RAY
;
run;&lt;/LI-CODE&gt;&lt;P&gt;I have used the following codes to address the different formats:&lt;/P&gt;&lt;P&gt;if scan(Names,-1,' ')=' MD. ' then Name_temp=tranwrd(Names,' MD. ',' MD ');&lt;BR /&gt;if scan(Names,-1,' ')=' M.D. ' then Name_temp=tranwrd(Names,' M.D. ',' MD ');&lt;BR /&gt;if scan(Names,-1,' ')='M.D.' then Name_temp=tranwrd(Names,'M.D.','MD');&lt;BR /&gt;if scan(Names,-1,' ')=',M.D.' then Name_temp=tranwrd(Names,',M.D.',' MD ');&lt;BR /&gt;if scan(Names,-1,' ')=' M.D.' then Name_temp=tranwrd(Names,' M.D.',' MD ');&lt;BR /&gt;if scan(Names,-1,' ')=' M.D ' then Name_temp=tranwrd(Names,' M.D ',' MD ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;But only the first name is getting converted.&lt;/P&gt;&lt;P&gt;Let me know what I can do get this output&lt;/P&gt;&lt;P&gt;Obs Names&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Name_temp&lt;/P&gt;&lt;P&gt;1 AARON RAY, M.D.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AARON RAY, MD&lt;BR /&gt;2 AARON,RAY MD.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AARON RAY, MD&lt;BR /&gt;3 RAY,AARON,M.D.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AARON RAY, MD&lt;BR /&gt;4 PMD RAY ARON M.D&amp;nbsp; &amp;nbsp; &amp;nbsp;AARON RAY, MD&lt;BR /&gt;5 AARON MD RAY&lt;BR /&gt;6 AARON RAY&lt;/P&gt;</description>
    <pubDate>Fri, 26 Feb 2021 01:25:42 GMT</pubDate>
    <dc:creator>Priyamvada07</dc:creator>
    <dc:date>2021-02-26T01:25:42Z</dc:date>
    <item>
      <title>Replace last word with another word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-last-word-with-another-word/m-p/722026#M223835</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp; have the following dataset and want to replace the last word if it is 'MD' or 'M.D.' or 'MD.' with 'MD'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;DATA EXAMPLE1;
  INPUT Names $char30.;
DATALINES;
AARON RAY, M.D.
AARON,RAY MD.
RAY,AARON,M.D.
PMD RAY ARON M.D
AARON MD RAY 
AARON RAY
;
run;&lt;/LI-CODE&gt;&lt;P&gt;I have used the following codes to address the different formats:&lt;/P&gt;&lt;P&gt;if scan(Names,-1,' ')=' MD. ' then Name_temp=tranwrd(Names,' MD. ',' MD ');&lt;BR /&gt;if scan(Names,-1,' ')=' M.D. ' then Name_temp=tranwrd(Names,' M.D. ',' MD ');&lt;BR /&gt;if scan(Names,-1,' ')='M.D.' then Name_temp=tranwrd(Names,'M.D.','MD');&lt;BR /&gt;if scan(Names,-1,' ')=',M.D.' then Name_temp=tranwrd(Names,',M.D.',' MD ');&lt;BR /&gt;if scan(Names,-1,' ')=' M.D.' then Name_temp=tranwrd(Names,' M.D.',' MD ');&lt;BR /&gt;if scan(Names,-1,' ')=' M.D ' then Name_temp=tranwrd(Names,' M.D ',' MD ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;But only the first name is getting converted.&lt;/P&gt;&lt;P&gt;Let me know what I can do get this output&lt;/P&gt;&lt;P&gt;Obs Names&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Name_temp&lt;/P&gt;&lt;P&gt;1 AARON RAY, M.D.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AARON RAY, MD&lt;BR /&gt;2 AARON,RAY MD.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;AARON RAY, MD&lt;BR /&gt;3 RAY,AARON,M.D.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AARON RAY, MD&lt;BR /&gt;4 PMD RAY ARON M.D&amp;nbsp; &amp;nbsp; &amp;nbsp;AARON RAY, MD&lt;BR /&gt;5 AARON MD RAY&lt;BR /&gt;6 AARON RAY&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 01:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-last-word-with-another-word/m-p/722026#M223835</guid>
      <dc:creator>Priyamvada07</dc:creator>
      <dc:date>2021-02-26T01:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Replace last word with another word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-last-word-with-another-word/m-p/722028#M223837</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NEWNAME=prxchange('s/M\.?D.\.? *\Z/MD/,1,OLDNAME);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 01:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-last-word-with-another-word/m-p/722028#M223837</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-26T01:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: Replace last word with another word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-last-word-with-another-word/m-p/722062#M223855</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;Works perfectly! Code provided by someone on another community.&lt;BR /&gt;&lt;BR /&gt;data want;
    set example1;

    last_word = scan(names, -1, ', ');

    if(compress(last_word, '. ') = 'MD') 
        then name_temp = tranwrd(names, strip(last_word), 'MD');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Feb 2021 07:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-last-word-with-another-word/m-p/722062#M223855</guid>
      <dc:creator>Priyamvada07</dc:creator>
      <dc:date>2021-02-26T07:36:49Z</dc:date>
    </item>
  </channel>
</rss>

