<?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: Need  help with substr in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244835#M56103</link>
    <description>&lt;P&gt;Thank you all for the quick reply. The codes are very helpful.&lt;/P&gt;
&lt;P&gt;s&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2016 21:46:50 GMT</pubDate>
    <dc:creator>shalmali</dc:creator>
    <dc:date>2016-01-20T21:46:50Z</dc:date>
    <item>
      <title>Need  help with substr</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244508#M56080</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a list of fullnames and I want to separate the first name and the last name from the fullname. The names are not in the same format and hence the substr and the scan functions I tried are given me wrong output for some names. The names are as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fullname&lt;/P&gt;
&lt;P&gt;H FULLER&lt;/P&gt;
&lt;P&gt;WILLIAM D SMITHBURG&lt;/P&gt;
&lt;P&gt;BOONE POWELL JR.&lt;/P&gt;
&lt;P&gt;W. JAMES FARRELL&lt;/P&gt;
&lt;P&gt;SAMUEL C. SCOTT III&lt;/P&gt;
&lt;P&gt;DAVID A. L. OWEN, C.H., F.R.C.P.&lt;/P&gt;
&lt;P&gt;R. S. AUSTIN&lt;/P&gt;
&lt;P&gt;JAMES PACE&lt;/P&gt;
&lt;P&gt;Ann McLaughlin Korologos&lt;/P&gt;
&lt;P&gt;SUSAN CLARK-JOHNSON&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output I desire is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fullname &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; First_Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Last_Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;H FULLER &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; H &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;Fuller&lt;/P&gt;
&lt;P&gt;WILLIAM D SMITHBURG &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;William &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Smithburg&lt;/P&gt;
&lt;P&gt;BOONE POWELL JR. &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;Boone &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Powell&lt;/P&gt;
&lt;P&gt;W. JAMES FARRELL &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;W &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;Farrell &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAMUEL C. SCOTT III &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;Samuel &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Scott&lt;/P&gt;
&lt;P&gt;DAVID A. L. OWEN, C.H., F.R.C.P. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; David &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Owen&lt;/P&gt;
&lt;P&gt;R. S. AUSTIN &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; R &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; Austin&lt;/P&gt;
&lt;P&gt;JAMES PACE &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; &amp;nbsp; &amp;nbsp; &amp;nbsp;James &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pace&lt;/P&gt;
&lt;P&gt;Ann McLaughlin Korologos &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ann &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;Korologos&lt;/P&gt;
&lt;P&gt;SUSAN CLARK-JOHNSON &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Susan &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Clark-Johnson&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate if someone share a code with me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;S&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 18:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244508#M56080</guid>
      <dc:creator>shalmali</dc:creator>
      <dc:date>2016-01-19T18:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need  help with substr</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244515#M56081</link>
      <description>Take a look at the scan() function, it will get you closer.</description>
      <pubDate>Tue, 19 Jan 2016 18:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244515#M56081</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-19T18:59:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need  help with substr</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244531#M56083</link>
      <description>&lt;P&gt;Depending on the different formats and how long the list is you'll probably have to full around with this a little to get it right, but it's a good start and works with the current example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;infile cards dsd dlm='***';&lt;BR /&gt;informat fullname $35.;&lt;BR /&gt;format fullname $35.;&lt;BR /&gt;input Fullname;&lt;BR /&gt;cards;&lt;BR /&gt;H FULLER&lt;BR /&gt;WILLIAM D SMITHBURG&lt;BR /&gt;BOONE POWELL JR.&lt;BR /&gt;W. JAMES FARRELL&lt;BR /&gt;SAMUEL C. SCOTT III&lt;BR /&gt;DAVID A. L. OWEN, C.H., F.R.C.P.&lt;BR /&gt;R. S. AUSTIN&lt;BR /&gt;JAMES PACE&lt;BR /&gt;Ann McLaughlin Korologos&lt;BR /&gt;SUSAN CLARK-JOHNSON&lt;BR /&gt;;run;&lt;BR /&gt;&lt;BR /&gt;data want(keep=fullname first_name last_name);&lt;BR /&gt;set have;&lt;BR /&gt;First_Name=scan(fullname,1,' ');&lt;BR /&gt;Last_Name=scan(fullname,2,' ');&lt;BR /&gt;if length(last_name) &amp;lt; 3 then Last_Name = scan(fullname,3,' ');&lt;BR /&gt;if length(last_name) &amp;lt; 3 then Last_Name = scan(fullname,4,' ');&lt;BR /&gt;if length(scan(fullname,3,' ')) &amp;gt; 3 then last_name = scan(fullname,3,' ');&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 20:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244531#M56083</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-01-19T20:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Need  help with substr</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244541#M56084</link>
      <description>&lt;P&gt;Good luck; If your data entry folks weren't told to collect first, last and middle names plus suffixes such as Junior separately there is almost always going to be doubt in the end.&lt;/P&gt;
&lt;P&gt;What do you do (using code only) with&amp;nbsp;names like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Harry Paul&lt;/P&gt;
&lt;P&gt;Na Satook Jal&lt;/P&gt;
&lt;P&gt;Lee Li&lt;/P&gt;
&lt;P&gt;Cropper Kambrii Laree&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 20:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244541#M56084</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-19T20:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need  help with substr</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244557#M56085</link>
      <description>&lt;P&gt;As has been noted, this data is a mess and you will need to make further decisions about additional cases.&amp;nbsp; Here are just a couple of examples that will cause trouble and require changing the rules:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DR. SMITH&lt;/P&gt;
&lt;P&gt;PRINCE&lt;/P&gt;
&lt;P&gt;LEONARDO DA VINCI&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But given that you can always afford to take the first word as the first name, here is an approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;First_Name = scan(fullname, 1, ' ');&lt;/P&gt;
&lt;P&gt;do i=-1 to -5 by -1 until (done='Y');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Last_Name = scan(fullname, i, ' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if Last_Name not in ('III', 'JR', 'SR', 'MD') and index(Last_Name, '.')=0 then done='Y';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;Last_Name = compress(Last_Name, ',');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 22:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244557#M56085</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-01-19T22:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need  help with substr</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244596#M56090</link>
      <description>&lt;P&gt;Yes. The data is messed up . You need consider more rules to process such kind of data.&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 have;
input Fullname $80.;
cards;
H FULLER
WILLIAM D SMITHBURG
BOONE POWELL JR.
W. JAMES FARRELL
SAMUEL C. SCOTT III
DAVID A. L. OWEN, C.H., F.R.C.P.
R. S. AUSTIN
JAMES PACE
Ann McLaughlin Korologos
SUSAN CLARK-JOHNSON
;
run;
data want;
 set have;
 length First_Name  Last_Name  $ 20;
 First_Name=scan(Fullname,1,,'ka');
 Last_Name=scan(prxchange('s/[a-z]+\.|\bI+\b/ /i',-1,Fullname),-1,' ,');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Jan 2016 05:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244596#M56090</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-20T05:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need  help with substr</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244835#M56103</link>
      <description>&lt;P&gt;Thank you all for the quick reply. The codes are very helpful.&lt;/P&gt;
&lt;P&gt;s&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 21:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-with-substr/m-p/244835#M56103</guid>
      <dc:creator>shalmali</dc:creator>
      <dc:date>2016-01-20T21:46:50Z</dc:date>
    </item>
  </channel>
</rss>

