<?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: How to extract a specific string from large string where the location varies in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351740#M81896</link>
    <description>&lt;P&gt;please try perl regular expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Value&amp;amp;$100.;
cards;&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; &amp;nbsp; &amp;nbsp;
Z-Other Services mod 26 (2011) M. 90 Modifier 26 Required
Z-Other Services mod 26 (2011) M. 90Modifier 26 Required
;

data want ;
set have;
if prxmatch('m/\w\.\s\d+/',value)&amp;gt;0 then flag=substr(value,prxmatch('m/\w\.\s\d+/',value),5);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 20 Apr 2017 15:22:54 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2017-04-20T15:22:54Z</dc:date>
    <item>
      <title>How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351723#M81890</link>
      <description>&lt;P&gt;Good Morning everyone! I have a variable whose values can range from few words to much longer strings. Somewhere within those strings or in the end are "O. XX" or "M. XX" or "M.XXX" where XX are numbers. The numbers are generally two digits, but could be three digits also I only want to extract "O. XX" and "M. XX" from it. Few examples with want column-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No &amp;nbsp; &amp;nbsp;Value &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. &amp;nbsp; &amp;nbsp; &amp;nbsp;Z-Other Services mod 26 (2011) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M. 90&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M. 90&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Modifier 26 Required&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;2. &amp;nbsp; &amp;nbsp; &amp;nbsp;Z-Other Services mod 26 (2011) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M. 90&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M. 90&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Modifier 26 Required&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. &amp;nbsp; &amp;nbsp; &amp;nbsp; CASE MANAGEMENT&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; O. 13 &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;O. 13&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Z-RADIOLOGY SERVICES (2013) &amp;nbsp; &amp;nbsp; &amp;nbsp;M.101&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M.101&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 14:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351723#M81890</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-04-20T14:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351735#M81893</link>
      <description>&lt;P&gt;Good time for a regular expression? Depending on your data, you might have to tweak it a little. For example, it wasn't clear that the space after the M/O would always be there, but this should get you started.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    txt = 'Z-Other Services mod 26 (2011) M. 90 Modifier 26 Required'; output;
    txt = 'Z-Other Services mod 26 (2011) M. 90'; output;
    txt = 'CASE MANAGEMENT O. 13'; output;
    txt = 'Z-RADIOLOGY SERVICES (2013) M. 101'; output;
run;

data want;
    set have;
    prx = prxparse('/(\s)([A-Z]\.\s\d{2,3})(\b)/');
    if prxmatch(prx, txt) then do;
        code = prxposn(prx, 2, txt);
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 15:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351735#M81893</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-04-20T15:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351738#M81894</link>
      <description>&lt;P&gt;Thats not how your data looks is it, you have copied that from Excel. &amp;nbsp;&lt;STRONG&gt;Post test data in the form of a datastep!!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will likely be quickest off using prxmatch,but if your string only contains the one "." then you could also do:&lt;/P&gt;
&lt;PRE&gt;want=substr(value,index(value,".")-1,index(value,".")+4);
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 15:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351738#M81894</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-20T15:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351740#M81896</link>
      <description>&lt;P&gt;please try perl regular expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Value&amp;amp;$100.;
cards;&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; &amp;nbsp; &amp;nbsp;
Z-Other Services mod 26 (2011) M. 90 Modifier 26 Required
Z-Other Services mod 26 (2011) M. 90Modifier 26 Required
;

data want ;
set have;
if prxmatch('m/\w\.\s\d+/',value)&amp;gt;0 then flag=substr(value,prxmatch('m/\w\.\s\d+/',value),5);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 15:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351740#M81896</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-04-20T15:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351742#M81898</link>
      <description>&lt;P&gt;Thanks so much! I will check it now..to answer your question, the space after O or M is generally there but in some cases, there is no space. Will that change the code a bit?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 15:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351742#M81898</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-04-20T15:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351743#M81899</link>
      <description>&lt;P&gt;Adding the ? makes the \s (space) optional:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prx &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;prxparse&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'/(\s)([A-Z]\.\s?\d{2,3})(\b)/'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 15:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351743#M81899</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-04-20T15:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351790#M81918</link>
      <description>&lt;P&gt;Thanks again! Yes, it works now for the most part, sorry i just forgot to mention that integers after O. or M. could be just 1 integer too, not only 2 or 3. For instance, there could be a string like below which draws a blank with existing code rather than desired O. 5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AMBULANCE ATTENDANT SERVICESO. 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried tweaking your code by adding 1 inside the bracket after d, like this, but it didnt work-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want1;&lt;BR /&gt; set kirk2;&lt;BR /&gt; prx = prxparse('/(\s)([A-Z]\.\s?\d{1,2,3})(\b)/');&lt;BR /&gt; if prxmatch(prx, Contract_Term_Name__Long_Descrip) then do;&lt;BR /&gt; code = prxposn(prx, 2, Contract_Term_Name__Long_Descrip);&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 16:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351790#M81918</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-04-20T16:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351791#M81919</link>
      <description>&lt;P&gt;prx = prxparse('/(\s)([A-Z]\.\s?\d{1,3})(\b)/');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The \d{1,3} means from 1 to 3 digits.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 16:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351791#M81919</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-04-20T16:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a specific string from large string where the location varies</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351792#M81920</link>
      <description>&lt;P&gt;Thanks so much!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 16:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-specific-string-from-large-string-where-the/m-p/351792#M81920</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-04-20T16:43:55Z</dc:date>
    </item>
  </channel>
</rss>

