<?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: PROC SQL: REMOVING MIDDLE INITIAL FROM STRING in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333842#M272166</link>
    <description>&lt;P&gt;It depends on how consistently the names are formatted but you could try a regex. The below is not tested, but the idea to find a space followed by a single character and remove it before using the scan.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;scan(prxchange('s/\s\w$//', 1, strip(&lt;SPAN&gt;FULL_NAME))&lt;/SPAN&gt;, -&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first_name&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Feb 2017 16:58:34 GMT</pubDate>
    <dc:creator>collinelliot</dc:creator>
    <dc:date>2017-02-17T16:58:34Z</dc:date>
    <item>
      <title>PROC SQL: REMOVING MIDDLE INITIAL FROM STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333825#M272165</link>
      <description>&lt;P&gt;Using PROC SQL, is it possible to remove the Middle Initial (if it is present) from the created First_Name variable in the SQL below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Smith, John M&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SQL below returns&lt;/P&gt;
&lt;P&gt;Smith, John M&lt;/P&gt;
&lt;P&gt;John M&lt;/P&gt;
&lt;P&gt;Smith&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need to remove the middle initial 'M' where present from first_name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I have so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Select&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; FULL_NAME&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;,scan(&lt;SPAN&gt;FULL_NAME&lt;/SPAN&gt;,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first_name&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;,scan(&lt;SPAN&gt;FULL_NAME&lt;/SPAN&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; last_name&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;FROM&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SAMPLE_TABLE&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 16:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333825#M272165</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2017-02-17T16:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: REMOVING MIDDLE INITIAL FROM STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333842#M272166</link>
      <description>&lt;P&gt;It depends on how consistently the names are formatted but you could try a regex. The below is not tested, but the idea to find a space followed by a single character and remove it before using the scan.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;scan(prxchange('s/\s\w$//', 1, strip(&lt;SPAN&gt;FULL_NAME))&lt;/SPAN&gt;, -&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first_name&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 16:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333842#M272166</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-02-17T16:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: REMOVING MIDDLE INITIAL FROM STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333845#M272167</link>
      <description>&lt;P&gt;Your code was close:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data sample_table;
  informat full_name $50.;
  input full_name &amp;amp;;
  cards;
Smith, John M
Smith, Joe
Smith, Mary Margaret
Smit, Margaret M
;

proc sql;
  create table want as
    Select
        FULL_NAME,
        scan(FULL_NAME,1,' ,') as last_name,
        scan(FULL_NAME,1-countw(full_name),' ,') as first_name
      from SAMPLE_TABLE
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 17:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333845#M272167</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-17T17:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: REMOVING MIDDLE INITIAL FROM STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333865#M272168</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table result as
   select scan( source,1,',' ) as surname length=12 
        , case when length( scan( source, -1, ' ' ) )  &amp;gt; 1 
               then scan( source, -1, ' ' ) 
               when length( scan( source, -2, ' ' ) )  &amp;gt; 1     
               then scan( source, -2, ' ' )
               else scan( source, -3, ' ' )
           end as forename length= 12    
      from source_data
             ;
quit ;
      &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 17:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333865#M272168</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-02-17T17:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: REMOVING MIDDLE INITIAL FROM STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333971#M272169</link>
      <description>&lt;P&gt;Thank you all for the help! That did the trick!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 21:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333971#M272169</guid>
      <dc:creator>PhatRam33</dc:creator>
      <dc:date>2017-02-17T21:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL: REMOVING MIDDLE INITIAL FROM STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333977#M272170</link>
      <description>&lt;P&gt;Regular expressions are most flexible&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
name = "George W. Bush"; output;
name = "George W Bush"; output;
name = "George Bush"; output;
run;

proc sql;
select name, 
    prxChange("s/(\w+\s)(\s*\w\.?\s+)(\w+)/\1\3/io",1,name) as shortName
from a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remember: prxChange returns the original string when the pattern is not found.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 21:46:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-REMOVING-MIDDLE-INITIAL-FROM-STRING/m-p/333977#M272170</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-02-17T21:46:31Z</dc:date>
    </item>
  </channel>
</rss>

