<?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: split strings based on a list of specific strings and stop the process when first meeting them in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558192#M155765</link>
    <description>&lt;P&gt;This should get you ahead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input NAME :&amp;amp; $500.;
cards;
3M CO (MINNESOTA MINING AND MANUFACTURING CO) 
3M CO 'MINNESOTA MINING AND MANUFACTURING CO' 
3M CO "MINNESOTA MINING AND MANUFACTURING CO" 
3M CO (MINNESOTA MINING AND MANUFACTURING CO) A LTD IN UK 
3M CO 'MINNESOTA MINING AND MANUFACTURING CO' A UK CO 
3M CO "MINNESOTA MINING AND MANUFACTURING CO" A UK LTD 
ARCH TIMBER PROTECTION LTD A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM 
run;    

data WANT;
  set HAVE;
  array SUFFIX[22] $6 _temporary_( 
                        'LTD   '
                        'CO    '  'CO LTD'
                        'INC   '
                        'PLC   '
                        'SPA   '
                        'LLP   '
                        'LLC   '
                        'LC    '
                        'AB    '
                        'AG    '
                        'SA    '
                        'SAS   '
                        'SAL   '
                        'SPA   '
                        'SRO   '
                        'SRL   '
                        'GMBH  '
                        'KK    '
                        'BV    '
                        'CP    '
                        'NL    '
                        ) ;    
  do I=1 to 26;
    STR= '/(.*? '||trim(SUFFIX[I])||'( \(.*\)| ".*"| ''.*'')? )/';
    REGEX= prxparse(STR);
    call prxsubstr(REGEX,NAME,POS,LEN);
    if POS then do;
      SUBSTR1=substr(NAME,POS,LEN);
      output; 
      leave;
    end;
  end;
run;   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;SUBSTR1&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO'&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO"&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO) A LTD&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO' A UK CO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO" A UK LTD&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;ARCH TIMBER PROTECTION LTD&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 May 2019 05:37:30 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-05-13T05:37:30Z</dc:date>
    <item>
      <title>split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/557839#M155571</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I split strings based on a list of specific strings (i.e., LTD, CO, LTD CO) and stop the process when&amp;nbsp;first meeting them.&lt;/P&gt;&lt;P&gt;during the process,&lt;/P&gt;&lt;P&gt;1.I expect not to process brackets( i.e., (), [], {}, ' ', " ") and strings among brackets during the process.&lt;/P&gt;&lt;P&gt;2.split the substrings to a new variable 'NAME_address'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input NAME: &amp;amp;$500.;
cards;
3M CO (MINNESOTA MINING AND MANUFACTURING CO) 
3M CO 'MINNESOTA MINING AND MANUFACTURING CO' 
3M CO "MINNESOTA MINING AND MANUFACTURING CO" &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO) A LTD IN UK 
3M CO 'MINNESOTA MINING AND MANUFACTURING CO' A UK CO 
3M CO "MINNESOTA MINING AND MANUFACTURING CO" A UK LTD 
ARCH TIMBER PROTECTION LTD A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM 
run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I expect to get the variable 'NAME_B' and 'NAME_address' from variable 'NAME'&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;TD&gt;NAME_B&lt;/TD&gt;&lt;TD&gt;NAME_address&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO)&lt;/TD&gt;&lt;TD&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO)&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO'&lt;/TD&gt;&lt;TD&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO'&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO"&lt;/TD&gt;&lt;TD&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO"&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO) A LTD IN UK&lt;/TD&gt;&lt;TD&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO)&lt;/TD&gt;&lt;TD&gt;A LTD IN UK&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO' A UK CO&lt;/TD&gt;&lt;TD&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO'&lt;/TD&gt;&lt;TD&gt;A UK CO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO" A UK LTD&lt;/TD&gt;&lt;TD&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO"&lt;/TD&gt;&lt;TD&gt;A UK LTD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ARCH TIMBER PROTECTION LTD A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM&lt;/TD&gt;&lt;TD&gt;ARCH TIMBER PROTECTION LTD&lt;/TD&gt;&lt;TD&gt;A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please give me some suggestions about this? thanks in advance.&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 04:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/557839#M155571</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-05-11T04:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558110#M155726</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before you even attempt to code for this you need to formulate the rules (exhaustive).&lt;/P&gt;
&lt;P&gt;You show us what you want but I wouldn't know how to come up with a set of rules which also covers your last case not only for exactly your sample data.&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2019 06:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558110#M155726</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-12T06:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558116#M155729</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your reply. I expect to use the code to clean the company name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so, I would like to separate 'NAME' variable into two new variables, the first is 'NAME_B' variable which only includes strings relevant to the company name, the second variable is 'NAME_address' variable which only includes strings relevant to address.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;by using the following company name in table 1 as an example&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;table1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO'&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO"&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO) A LTD IN UK&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO' A UK CO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO" A UK LTD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ARCH TIMBER PROTECTION LTD A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for value 3M CO (MINNESOTA MINING AND MANUFACTURING CO), '3M CO' is the abbreviation of 'MINNESOTA MINING AND MANUFACTURING CO', and I expect to put them together into 'NAME_B'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for value&amp;nbsp;3M CO 'MINNESOTA MINING AND MANUFACTURING CO' &lt;FONT color="#FF0000"&gt;A UK CO&lt;/FONT&gt;,&amp;nbsp; " 3M CO 'MINNESOTA MINING AND MANUFACTURING CO' " should belong to 'NAME_B' and '&lt;FONT color="#FF0000"&gt;A UK CO' &lt;FONT color="#000000"&gt;is an introduction of 3M company, which I expect to split into a new variable named 'NAME_address'.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;I expect to separate the 'NAME' variable based on 'CO', 'LTD' and 'LTD CO', as they are usually the ending value of a company name.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;However,&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;for value '&lt;STRONG&gt;ARCH TIMBER PROTECTION &lt;FONT color="#FF0000"&gt;LTD&lt;/FONT&gt;&lt;/STRONG&gt; &lt;U&gt;A PRIVATE&lt;FONT color="#FF0000"&gt; LTD CO&lt;/FONT&gt; ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM&lt;/U&gt;',&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;'&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;ARCH TIMBER PROTECTION &lt;/STRONG&gt;&lt;FONT color="#FF0000"&gt;LTD&lt;/FONT&gt;' is the name of the company, and '&lt;U&gt;A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM&lt;/U&gt;' is the introduction of the company, so I expect to split them into two different variables, which are&amp;nbsp;'NAME_B',&amp;nbsp;'NAME_address'. But they both include 'LTD' and 'LTD CO', so I expect to stop the process after getting the first company suffix ( in this example, it is 'LTD').&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;that is what I expect to do. Could you please give me some suggestions about this, please let me know if you have any question.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;thanks in advance.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2019 09:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558116#M155729</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-05-12T09:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558163#M155748</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You showed us first how the desired result should look like. Now you explain us the reasons why you want the result to look this way. BUT: That still doesn't give us the RULES how to split strings to create such a result.&lt;/P&gt;
&lt;P&gt;I assume you're after code which also works for other names and not just exactly for what you've posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example for below:&lt;/P&gt;
&lt;PRE&gt;for value 3M CO (MINNESOTA MINING AND MANUFACTURING CO), '3M CO' is the abbreviation of 'MINNESOTA MINING AND MANUFACTURING CO', and I expect to put them together into 'NAME_B'.&lt;/PRE&gt;
&lt;P&gt;What's the rule for a computer to "know" that this is an abbreviation? Do you have somewhere a list of such abbreviations where we could look up?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;I expect to separate the 'NAME' variable based on 'CO', 'LTD' and 'LTD CO', as they are usually the ending value of a company name.&lt;/PRE&gt;
&lt;P&gt;"USUALLY" might give you the generic rule - but then you need clear rules for all the exceptions. Looking at your sample data it also appears that you don't want to just split before LTD or CO but also want to include some more "leading" words.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your sample data a rule could be to split after the first CO immediately followed by a non-letter character. But I guess that would only be appropriate for your sample data and we would still need some exception rules for your last case and for "abbreviations".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So... Try to formulate rules which are &lt;STRONG&gt;exclusive&lt;/STRONG&gt; and &lt;STRONG&gt;exhaustive&lt;/STRONG&gt; and post them. Then we can help you with the coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2019 23:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558163#M155748</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-12T23:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558177#M155755</link>
      <description>&lt;P&gt;dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yes,&amp;nbsp; it is my expectation basically.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;a rule could be to split after the first&lt;FONT color="#FF0000"&gt; CO&lt;/FONT&gt; immediately followed by a&lt;FONT color="#FF0000"&gt; non-letter character.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;except for&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;non-letter character.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I expect not &lt;SPAN&gt;followed by a&lt;FONT color="#FF0000"&gt; non-letter character&lt;FONT color="#000000"&gt;, but these five group characters, i.e., &lt;FONT color="#FF0000"&gt;(), [], {}, ' ', " "&lt;/FONT&gt;,&amp;nbsp; and strings among them. such as&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;&amp;lt;span class="token string"&amp;gt;&amp;lt;span class="token punctuation"&amp;gt;(&amp;lt;/span&amp;gt;MINNESOTA MINING AND MANUFACTURING CO&amp;lt;span class="token punctuation"&amp;gt;)&amp;lt;br /&amp;gt;[MINNESOTA MINING AND MANUFACTURING CO]&amp;lt;br /&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;span class="token punctuation"&amp;gt;{MINNESOTA MINING AND MANUFACTURING CO}&amp;lt;/span&amp;gt;&amp;lt;br /&amp;gt;'MINNESOTA MINING AND MANUFACTURING CO'&amp;lt;/span&amp;gt; &amp;lt;br /&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;rather than&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(MINNESOTA MINING AND MANUFACTURING CO&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(MINNESOTA MINING AND MANUFACTURING CO'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Besides, the list of company suffix except for 'CO' is&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 NAME: &amp;amp;$500.;
cards;
LTD
CO LTD
INC  
PLC
SPA
LLP
LLC
LC
AB
AG
SA
SAS
SAL
SPA
SRO
SRL
GMBH
KK
BV
CP
NL
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;please let me know if it is not clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 02:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558177#M155755</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-05-13T02:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558190#M155764</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From my point of view YOU need to inspect your data and then actually fully define the rules you need implemented (=clearly and explicitly formulated "black and white" rules and not "could be").&lt;/P&gt;
&lt;P&gt;Create representative sample data (have) - best using your real data - and define the outcome. The first test of your rules is then just going over your sample have data (eventually take a 2nd and different sample from your actual data) and determine if the rules would work to get to the desired outcome (a "desk" test without writing any code). Only when satisfied with the "desk" test actual program design and coding should start.&lt;/P&gt;
&lt;P&gt;Sooo... I suggest you try and get to the point where you've got fully formulated and tested rules.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you then want coding help provide representative sample data (have) required to implement and unit test these rules via SAS code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF you don't define and verify the rules upfront then what's likely going to happen: You will get SAS code from us which does the things you've told us already for the data you've provided; but then when you use this code for your real data there will always be additional cases and you will continue to ask for changes and other stuff. That's why spending the time for proper analysis and rule formulation will get you faster to the desired outcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to give you an example for a rule:&lt;/P&gt;
&lt;P&gt;1. First occurrence of word CO &amp;lt;or here reference to list of word&amp;gt; immediately followed by any of the following characters &amp;lt;list of characters&amp;gt;: Split string, assign everything after the list of characters to &amp;lt;2nd variable&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also consider that rules might be hierarchical like: only apply 2nd rule if first rule doesn't apply. You will also have to define this hierarchy.&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 05:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558190#M155764</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-13T05:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558192#M155765</link>
      <description>&lt;P&gt;This should get you ahead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input NAME :&amp;amp; $500.;
cards;
3M CO (MINNESOTA MINING AND MANUFACTURING CO) 
3M CO 'MINNESOTA MINING AND MANUFACTURING CO' 
3M CO "MINNESOTA MINING AND MANUFACTURING CO" 
3M CO (MINNESOTA MINING AND MANUFACTURING CO) A LTD IN UK 
3M CO 'MINNESOTA MINING AND MANUFACTURING CO' A UK CO 
3M CO "MINNESOTA MINING AND MANUFACTURING CO" A UK LTD 
ARCH TIMBER PROTECTION LTD A PRIVATE LTD CO ORGANISED UNDER THE LAWS OF THE UNITED KINDGOM 
run;    

data WANT;
  set HAVE;
  array SUFFIX[22] $6 _temporary_( 
                        'LTD   '
                        'CO    '  'CO LTD'
                        'INC   '
                        'PLC   '
                        'SPA   '
                        'LLP   '
                        'LLC   '
                        'LC    '
                        'AB    '
                        'AG    '
                        'SA    '
                        'SAS   '
                        'SAL   '
                        'SPA   '
                        'SRO   '
                        'SRL   '
                        'GMBH  '
                        'KK    '
                        'BV    '
                        'CP    '
                        'NL    '
                        ) ;    
  do I=1 to 26;
    STR= '/(.*? '||trim(SUFFIX[I])||'( \(.*\)| ".*"| ''.*'')? )/';
    REGEX= prxparse(STR);
    call prxsubstr(REGEX,NAME,POS,LEN);
    if POS then do;
      SUBSTR1=substr(NAME,POS,LEN);
      output; 
      leave;
    end;
  end;
run;   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;SUBSTR1&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO'&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO"&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO) A LTD&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO' A UK CO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO" A UK LTD&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;ARCH TIMBER PROTECTION LTD&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2019 05:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/558192#M155765</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-13T05:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/559989#M156460</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your&amp;nbsp;amazing codes. it is very helpful for my work. however, the code does not fit the following strings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;M CO &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;MINNESOTA MINING AND MANUFACTURING CO&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; A LTD &lt;SPAN class="token operator"&gt;IN&lt;/SPAN&gt; UK 
&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;M CO &lt;SPAN class="token string"&gt;'MINNESOTA MINING AND MANUFACTURING CO'&lt;/SPAN&gt; A UK CO 
&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;M CO &lt;SPAN class="token string"&gt;"MINNESOTA MINING AND MANUFACTURING CO"&lt;/SPAN&gt; A UK LTD &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;which finally get.&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;3M &lt;FONT color="#FF0000"&gt;CO&lt;/FONT&gt; (MINNESOTA MINING AND MANUFACTURING CO) A LTD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M &lt;FONT color="#FF0000"&gt;CO&lt;/FONT&gt; 'MINNESOTA MINING AND MANUFACTURING CO' A UK CO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3M &lt;FONT color="#FF0000"&gt;CO&lt;/FONT&gt; "MINNESOTA MINING AND MANUFACTURING CO" A UK LTD&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;How can I only process the first string which in the list?&lt;/P&gt;&lt;P&gt;Could you please give me some suggestions about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 01:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/559989#M156460</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-05-20T01:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: split strings based on a list of specific strings and stop the process when first meeting them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/559993#M156463</link>
      <description>&lt;P&gt;If you swap the positions of&amp;nbsp; LTD and CO in&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token statement"&gt;array&lt;/SPAN&gt; SUFFIX&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;22&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;6&lt;/SPAN&gt; _temporary_&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; 
                        &lt;SPAN class="token string"&gt;'LTD   '&lt;/SPAN&gt;
                        &lt;SPAN class="token string"&gt;'CO    '&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it will work for these companies.&lt;/P&gt;
&lt;P&gt;See:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SUBSTR1&lt;/STRONG&gt;&lt;BR /&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO)&lt;BR /&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO'&lt;BR /&gt;3M CO "MINNESOTA MINING AND MANUFACTURING CO"&lt;BR /&gt;3M CO (MINNESOTA MINING AND MANUFACTURING CO)&lt;BR /&gt;3M CO 'MINNESOTA MINING AND MANUFACTURING CO'&lt;BR /&gt;ARCH TIMBER PROTECTION LTD A PRIVATE LTD CO&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code was given as a template, not a solution.&lt;/P&gt;
&lt;P&gt;You have to modify it to match your data and your needs.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 02:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-strings-based-on-a-list-of-specific-strings-and-stop-the/m-p/559993#M156463</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-20T02:47:45Z</dc:date>
    </item>
  </channel>
</rss>

