<?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: Extract first and last name from character variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674898#M23591</link>
    <description>&lt;P&gt;As soon as personal names are involved, sooner or later things will get interesting. Without a proper delimiter between first-name and last-name this problem can't be solved, because the number of words forming first-name and last-name is rarely two (one word for each), starting the interesting part: from the second to the next-to-last word you have to decide, whether the word belongs to first-name or last-name. This is pure guesswork and will not lead to usable results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following step extracts the names and stores in in one variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   
   length FullName $ 40 rxName 8;
   retain rxName;
   drop rxName;
   
   if _n_ = 1 then do;
      rxName = prxparse('/requestor:_(.+)_reason/i');
   end;
   
   if prxmatch(rxName, note) then do;
      FullName = prxposn(rxName, 1, note);
      FullName = translate(FullName, ' ', '_');
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Aug 2020 05:26:33 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-08-06T05:26:33Z</dc:date>
    <item>
      <title>Extract first and last name from character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674887#M23589</link>
      <description>&lt;P&gt;I have a variable that has a first name and last name embedded in it. How can I extract the name into a new variable, assuming it always comes after "Requestor: " and before "Reason:"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
 length note $200.;
 input note $ ;
cards;
This_is_the_Requestor:_Mary_L._Santiago_Reason:
Additional_text_This_is_the_Requestor:_John_Doe_Reason:_stuff
This_is_the_Requestor:_Tyler_Nguyen_Reason:_text_text
;
run;

data have;
 set have;
 note = tranwrd ( note, "_", " " );
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 01:51:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674887#M23589</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2020-08-06T01:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extract first and last name from character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674894#M23590</link>
      <description>&lt;P&gt;The delimiter between the two names id ":" then:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first_name = scan(note,1,":");
second_name = scan(note,2,":");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 04:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674894#M23590</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-06T04:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extract first and last name from character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674898#M23591</link>
      <description>&lt;P&gt;As soon as personal names are involved, sooner or later things will get interesting. Without a proper delimiter between first-name and last-name this problem can't be solved, because the number of words forming first-name and last-name is rarely two (one word for each), starting the interesting part: from the second to the next-to-last word you have to decide, whether the word belongs to first-name or last-name. This is pure guesswork and will not lead to usable results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following step extracts the names and stores in in one variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   
   length FullName $ 40 rxName 8;
   retain rxName;
   drop rxName;
   
   if _n_ = 1 then do;
      rxName = prxparse('/requestor:_(.+)_reason/i');
   end;
   
   if prxmatch(rxName, note) then do;
      FullName = prxposn(rxName, 1, note);
      FullName = translate(FullName, ' ', '_');
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 05:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674898#M23591</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-06T05:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extract first and last name from character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674904#M23592</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
length name $30;
note = scan(note,2,':');
call scan(note,-1,pos,le,'_','m');
name = translate(substr(note,2,pos - 2),' ','_');
keep name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 06:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674904#M23592</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-06T06:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extract first and last name from character variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674913#M23593</link>
      <description>&lt;P&gt;Sorry, it seems that I had some misunderstanding;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
 length note $200.;
 input note $ ;
 note = tranwrd ( note, "_", " " );
cards;
This_is_the_Requestor:_Mary_L._Santiago_Reason:
Additional_text_This_is_the_Requestor:_John_Doe_Reason:_stuff
This_is_the_Requestor:_Tyler_Nguyen_Reason:_text_text
;
run;

data want;
 set have;
     pos1 = findw(note,"Requestor:");
     pos2 = findw(note,"Reason:");
     fullname = strip(substr(note,pos1+10,pos2-pos1-10));&lt;BR /&gt;     drop pos1 pos2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 07:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-first-and-last-name-from-character-variable/m-p/674913#M23593</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-06T07:31:38Z</dc:date>
    </item>
  </channel>
</rss>

