<?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: Parse character string with multiple delimiters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588210#M168078</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/182665"&gt;@SasPerson85&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yup exactly two words to match in each obs.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then take two words out of the string at a time.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  length name $200;
  do i=1 by 2 until (name=' ');
     name=catx(' ',scan(var,i,' ,;'),scan(var,i+1,' ,;'));
     if i=1 or name ne ' ' then output;
  end;
  drop var;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs          name            i

 1     Gabriella Cornish     1
 2     Kenny Rooney          3
 3     Rupert Pickett        5
 4     Brett Mcnally         7
 5     Ishmael Khan          9
 6     Kaitlan Wallace      11
 7     Elyse Marriott       13
 8     Dollie Parry         15


&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Sep 2019 13:16:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-09-12T13:16:53Z</dc:date>
    <item>
      <title>Parse character string with multiple delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588033#M168000</link>
      <description>&lt;P&gt;I have a single observation dataset that contains peoples first and last names. There are multiple delimiters involved as it comes from a free form text field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of a string:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;var&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Gabriella Cornish Kenny Rooney, Rupert Pickett,Brett Mcnally; Ishmael Khan Kaitlan Wallace, Elyse Marriott, Dollie Parry&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this string there are space, comma, and semicolon delimiters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the output dataset to look like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;var&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Gabriella Cornish&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Kenny Rooney&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Rupert Pickett&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Brett Mcnally&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Ishmael Khan&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Kaitlan Wallace&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Elyse Marriott&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Dollie Parry&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically I need someway (I don't care which why; macro, datastep, sql etc.) that is very dynamic and can handle a variety of delimiters as well as multiple lengths.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 21:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588033#M168000</guid>
      <dc:creator>SasPerson85</dc:creator>
      <dc:date>2019-09-11T21:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Parse character string with multiple delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588035#M168001</link>
      <description>&lt;P&gt;Please try below considering that the names are a combination of two words (first &amp;amp; last name or last or first name)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var&amp;amp;$200.;
datalines4;
Gabriella Cornish Kenny Rooney, Rupert Pickett,Brett Mcnally; Ishmael Khan Kaitlan Wallace, Elyse Marriott, Dollie Parry
;;;;

data want;
set have;
retain var2;
do i = 1 to countw(var,' ,;')-1;
var2=catx(' ',scan(var,i,' ,;'),scan(var,i+1,' ,;'));
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 21:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588035#M168001</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-09-11T21:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Parse character string with multiple delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588058#M168011</link>
      <description>&lt;P&gt;Or sometimes three or more words:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Paul Le Blanc&lt;/P&gt;
&lt;P&gt;Eric von Lustbader&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't forget that some people include things like: Junior, Senior, II, III, IV, and some times Doctor, Esquire, and other fussiness.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel your pain. I would tend to split the data into records at the comma and semicolon, unless you have some entries that are using Lastname, Firstname before tackling the space delimited bit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data temp;
  set have;
  length name $ 50.;
  do i= 1 to (countw(var,',;'));
   name= strip(scan(var,i,',;'));
   problem = (countw(name) ne 2);
   output;
  end;
  drop i var;
run;&lt;/PRE&gt;
&lt;P&gt;The ones where problem = 1 may require additional work. Some may yield to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;'s bit of pulling things out 2 at a time. But where to deal with 3 or 5 or more name elements may require manual processing.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 22:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588058#M168011</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-11T22:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Parse character string with multiple delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588170#M168065</link>
      <description>&lt;P&gt;Is that exactly two words to match in an obs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm=' ,;';
input (first last) (: $40.) @@;
var=catx(' ',first,last);
datalines4;
Gabriella Cornish Kenny Rooney, Rupert Pickett,Brett Mcnally; Ishmael Khan Kaitlan Wallace, Elyse Marriott, Dollie Parry
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Sep 2019 11:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588170#M168065</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-09-12T11:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Parse character string with multiple delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588209#M168077</link>
      <description>Yup exactly two words to match in each obs.</description>
      <pubDate>Thu, 12 Sep 2019 13:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588209#M168077</guid>
      <dc:creator>SasPerson85</dc:creator>
      <dc:date>2019-09-12T13:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Parse character string with multiple delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588210#M168078</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/182665"&gt;@SasPerson85&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yup exactly two words to match in each obs.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then take two words out of the string at a time.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  length name $200;
  do i=1 by 2 until (name=' ');
     name=catx(' ',scan(var,i,' ,;'),scan(var,i+1,' ,;'));
     if i=1 or name ne ' ' then output;
  end;
  drop var;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs          name            i

 1     Gabriella Cornish     1
 2     Kenny Rooney          3
 3     Rupert Pickett        5
 4     Brett Mcnally         7
 5     Ishmael Khan          9
 6     Kaitlan Wallace      11
 7     Elyse Marriott       13
 8     Dollie Parry         15


&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Sep 2019 13:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-character-string-with-multiple-delimiters/m-p/588210#M168078</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-12T13:16:53Z</dc:date>
    </item>
  </channel>
</rss>

