<?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: Remove middle initial from LastName, FirstName M in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710665#M218819</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Name $20.;
cards;
Doe, John M.
Doe, Jane
;

data want;
 set have;
 length want $20;
 if countw(name,' ')=3 then want=substr(name,1,anyspace(strip(name),-99));
 else want=name;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Jan 2021 19:06:58 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2021-01-11T19:06:58Z</dc:date>
    <item>
      <title>Remove middle initial from LastName, FirstName M</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710661#M218818</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to remove middle initials at the end of a name IF it has a middle initial (some names don't have middle initial in the dataset).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I have:&lt;/P&gt;
&lt;TABLE style="width: 25%;" border="1" width="25%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Doe, John M.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Doe, Jane&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I'd like:&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Doe, John&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Doe, Jane&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've seen some different approaches, and it seems as though a substr(scan()) may be the best approach, I'm just not sure how to apply it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the below code, but it removed everything after the first space.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Name = substr(Name,1,length(Name) - length(scan(Name,-1,' ')));&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 18:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710661#M218818</guid>
      <dc:creator>BlayLay</dc:creator>
      <dc:date>2021-01-11T18:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Remove middle initial from LastName, FirstName M</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710665#M218819</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Name $20.;
cards;
Doe, John M.
Doe, Jane
;

data want;
 set have;
 length want $20;
 if countw(name,' ')=3 then want=substr(name,1,anyspace(strip(name),-99));
 else want=name;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jan 2021 19:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710665#M218819</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-11T19:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Remove middle initial from LastName, FirstName M</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710671#M218822</link>
      <description>&lt;P&gt;Or little cheeky-------------&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Name $20.;
cards;
Doe, John M.
Doe, Jane
;

data want;
 set have;
 length want $20;
 want=catx(' ',scan(name,1,' '),scan(name,2,' '));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jan 2021 19:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710671#M218822</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-11T19:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Remove middle initial from LastName, FirstName M</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710673#M218824</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;Appreciate the options, which one would you recommend from a performance/stability standpoint? They both seem to work, so wasn't sure if you had a preference based on your experience.</description>
      <pubDate>Mon, 11 Jan 2021 19:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710673#M218824</guid>
      <dc:creator>BlayLay</dc:creator>
      <dc:date>2021-01-11T19:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Remove middle initial from LastName, FirstName M</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710676#M218825</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349857"&gt;@BlayLay&lt;/a&gt;&amp;nbsp; Both approaches follow the logic-&lt;/P&gt;
&lt;P&gt;1. Check how many words are there in the name value.&lt;/P&gt;
&lt;P&gt;2. If there are 3 words(assuming the 3rd one is he middle initial to be ignored), just extract the 1st 2. Otherwise just take the name value as is.&lt;/P&gt;
&lt;P&gt;3. The 1st one uses SUBSTR to extract from position 1 up until the last delimiter ' ' that separates the words&lt;/P&gt;
&lt;P&gt;4. The 2nd approach basically extracts 1st word and 2nd word and concatenates into 1. A lazy approach so to speak.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's up to you and your convenience.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 20:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710676#M218825</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-11T20:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Remove middle initial from LastName, FirstName M</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710680#M218826</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/349857"&gt;@BlayLay&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;Appreciate the options, which one would you recommend from a performance/stability standpoint? They both seem to work, so wasn't sure if you had a preference based on your experience.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When it comes to names stored in a single variable I don't trust much of anything unless someone that is involved with creating the data promises, and will stand by their statement later, that "all the names are last, first with optional middle initial".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have received data with names that in a single file were:&lt;/P&gt;
&lt;P&gt;First name, last name, middle initial&lt;/P&gt;
&lt;P&gt;First name, last name, other parent's last name, middle name&lt;/P&gt;
&lt;P&gt;Last name, first name, other parent's last name, middle name&lt;/P&gt;
&lt;P&gt;Last name, other parent's last name, first name&lt;/P&gt;
&lt;P&gt;Last name -(hyphen character) other parent's last name, first name&lt;/P&gt;
&lt;P&gt;Sprinkle in random Junior, or "the Second" after any of the first or last names&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And one name like: Moon Beam Sun Child&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have occasional other elements like titles, "Dr." "Esq." you may have more fun with getting the right pieces together depending on order and consistency.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 20:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-middle-initial-from-LastName-FirstName-M/m-p/710680#M218826</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-11T20:30:27Z</dc:date>
    </item>
  </channel>
</rss>

