<?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: Question about extra comma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885316#M349819</link>
    <description>Tom, This is excellent. Thanks. We have solved elimination of the comma for the first observation, but now there's a guy with a Middle Initial following the second comma - see 4th line below. Would your code be the same for someone like him? Smith,Vincent, Dobbins,Tyrone G Smith, John Dobbins,Tyrone,L</description>
    <pubDate>Tue, 18 Jul 2023 16:59:37 GMT</pubDate>
    <dc:creator>Mary60</dc:creator>
    <dc:date>2023-07-18T16:59:37Z</dc:date>
    <item>
      <title>Question about extra comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885294#M349812</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Some of my output fields contain an extra comma at the end of the field. How can I eliminate that comma&lt;/P&gt;&lt;P&gt;For example, here is&amp;nbsp;a "bad" record for a single "name" field containing a second comma in red(bad):&lt;/P&gt;&lt;P&gt;Smith,Vincent&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;,&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Here is the "good" record that only contains one comma and a space, not a second comma for mname(good):&lt;/P&gt;&lt;P&gt;Dobbins,Tyrone G&lt;/P&gt;&lt;P&gt;Here is another "good" record without a middle name&lt;/P&gt;&lt;P&gt;Smith, John&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is how I am parsing the fname, mname and lname from the single "name" field, but the mname is giving me two fields mname&amp;nbsp;for Smith&lt;/P&gt;&lt;P&gt;DATA NAMEA; SET NAM1;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; X=INDEXC(NAME1,',');&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; Y=INDEXC(NAME1,' ');&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; LNAME1=SUBSTR(NAME1,1,X-1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; FNAME1=SUBSTR(NAME1,X+1, Y-X);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; MNAME1=SCAN(NAME1,3);&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; IF (MNAME1 =FNAME1 ) THEN&amp;nbsp; MNAME1=' ';&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the output on Vincent Smith, here's what I get:&lt;/P&gt;&lt;P&gt;VINCENT,, ,SMITH&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I need:&lt;/P&gt;&lt;P&gt;VINNY, ,SMITH&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I eliminate that second comma?&lt;/P&gt;&lt;P&gt;Thanks so much,&lt;/P&gt;&lt;P&gt;Mary&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 15:35:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885294#M349812</guid>
      <dc:creator>Mary60</dc:creator>
      <dc:date>2023-07-18T15:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Question about extra comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885295#M349813</link>
      <description>I meant I need the output VINCENT, ,SMITH</description>
      <pubDate>Tue, 18 Jul 2023 15:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885295#M349813</guid>
      <dc:creator>Mary60</dc:creator>
      <dc:date>2023-07-18T15:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Question about extra comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885314#M349817</link>
      <description>&lt;P&gt;It is confusing what is the input and what is the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you starting with these strings as your input?&lt;/P&gt;
&lt;PRE&gt;Smith,Vincent,
Dobbins,Tyrone G
Smith, John&lt;/PRE&gt;
&lt;P&gt;And what is the output you want?&lt;/P&gt;
&lt;P&gt;Do you want to make three variables with LAST, FIRST and MIDDLE names?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want to make a comma delimited list of LAST,MIDDLE,FIRST?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: you will have a lot of trouble with people that use a space in the middle of their FIRST or LAST name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To parse those input strings look for just the first comma location.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input string $50.;
cards;
Smith,Vincent,
Dobbins,Tyrone G
Smith, John
;

data want;
  set have;
  length first middle last new $50 ;
  loc=indexc(string,',');
  last=substr(string,1,loc-1);
  first=left(substr(string,loc+1));
  first=left(compbl(translate(first,' ',',')));
  loc=indexc(first,' ');
  middle=substr(first,loc+1);
  first=substr(first,1,loc-1);
  new =cat(trim(last),',',trim(middle),',',first);
  drop loc;
run;
proc print;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt; Obs         string         first      middle     last            new

  1     Smith,Vincent,      Vincent              Smith      Smith, ,Vincent
  2     Dobbins,Tyrone G    Tyrone       G       Dobbins    Dobbins,G,Tyrone
  3     Smith, John         John                 Smith      Smith, ,John
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 16:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885314#M349817</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-18T16:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Question about extra comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885316#M349819</link>
      <description>Tom, This is excellent. Thanks. We have solved elimination of the comma for the first observation, but now there's a guy with a Middle Initial following the second comma - see 4th line below. Would your code be the same for someone like him? Smith,Vincent, Dobbins,Tyrone G Smith, John Dobbins,Tyrone,L</description>
      <pubDate>Tue, 18 Jul 2023 16:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885316#M349819</guid>
      <dc:creator>Mary60</dc:creator>
      <dc:date>2023-07-18T16:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Question about extra comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885320#M349820</link>
      <description>&lt;P&gt;Just try it.&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;Obs         string         first      middle     last            new

  1     Smith,Vincent,      Vincent              Smith      Smith, ,Vincent
  2     Dobbins,Tyrone G    Tyrone       G       Dobbins    Dobbins,G,Tyrone
  3     Smith, John         John                 Smith      Smith, ,John
  4     Dobbins,Tyrone,L    Tyrone       L       Dobbins    Dobbins,L,Tyrone
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Tue, 18 Jul 2023 17:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-extra-comma/m-p/885320#M349820</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-18T17:12:05Z</dc:date>
    </item>
  </channel>
</rss>

