<?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 Number in a string with special charctes in middle of number with regular expression in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750588#M236122</link>
    <description>&lt;P&gt;It's really hard to create rules and then program them if all we have is just two examples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, a couple of questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Does the string always begin with the text &lt;FONT face="courier new,courier"&gt;'listing ' ?&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;Or does the string sometimes begin with other text ?&lt;/LI&gt;
&lt;LI&gt;Is there always a space before the numbers, or not?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;How about YOU tell us the rules for extracting the numbers of interest, and then we can show you code that might work.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Jun 2021 10:27:52 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-06-26T10:27:52Z</dc:date>
    <item>
      <title>Extract Number in a string with special charctes in middle of number with regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750587#M236121</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to extract the number from starting to end include special charcters.&lt;/P&gt;&lt;P&gt;String1: listing16-88-004 . subjects of devations . xlsx;&lt;/P&gt;&lt;P&gt;String2 : listing 16.88.004.&amp;nbsp;subjects of devations . xlsx;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need output from above tow string as below.&lt;/P&gt;&lt;P&gt;String1_output&amp;nbsp; = '16-88-004';&lt;/P&gt;&lt;P&gt;string2_output&amp;nbsp; &amp;nbsp;= '16.88.004';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Raja.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 10:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750587#M236121</guid>
      <dc:creator>raja777pharma</dc:creator>
      <dc:date>2021-06-26T10:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Number in a string with special charctes in middle of number with regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750588#M236122</link>
      <description>&lt;P&gt;It's really hard to create rules and then program them if all we have is just two examples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, a couple of questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Does the string always begin with the text &lt;FONT face="courier new,courier"&gt;'listing ' ?&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;Or does the string sometimes begin with other text ?&lt;/LI&gt;
&lt;LI&gt;Is there always a space before the numbers, or not?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;How about YOU tell us the rules for extracting the numbers of interest, and then we can show you code that might work.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 10:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750588#M236122</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-26T10:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Number in a string with special charctes in middle of number with regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750594#M236126</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input have $80.;
cards4;
String1: listing16-88-004 . subjects of devations . xlsx;
String2 : listing 16.88.004. subjects of devations . xlsx;
;;;;

data want;
 set have;
 pid=prxparse('/\d+\D\d+\D\d+/');
 call prxsubstr(pid,have,p,l);
 if p&amp;gt;0 then want=substr(have,p,l);
 drop pid p l;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Jun 2021 11:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750594#M236126</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-26T11:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Number in a string with special charctes in middle of number with regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750597#M236129</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please refer below ..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Does the string always begin with the text&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;'listing ' ?&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Ans : No&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;Or does the string sometimes begin with other text ?&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ans : Yes&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Is there always a space before the numbers, or not?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ans : Not alwas&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 12:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750597#M236129</guid>
      <dc:creator>raja777pharma</dc:creator>
      <dc:date>2021-06-26T12:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Number in a string with special charctes in middle of number with regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750598#M236130</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/309000"&gt;@raja777pharma&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer below ..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Does the string always begin with the text&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;'listing ' ?&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Ans : No&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;Or does the string sometimes begin with other text ?&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ans : Yes&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Is there always a space before the numbers, or not?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ans : Not alwas&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So please provide some rules (in words) that we can use to extract the numbers you want.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 14:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750598#M236130</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-26T14:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Number in a string with special charctes in middle of number with regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750600#M236131</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Miller,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My requirement is to extract numbers in text string as when number(s) present in middle of string with combined special charcters like '.' or '-' .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Rule 1 : Extract numeric string from start to end with special charcters.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string1 = 'Text charcters 1.2.34.16 text charcters many ' ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; string2 = '15-6-7.8 text charcters many ';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; string3&amp;nbsp; = 'text charctes words many 14-8-16-46 many alphabets';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Expected Out puts:&amp;nbsp;&amp;nbsp; want string&amp;nbsp; &amp;nbsp;= '1.2.34.16';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&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_strint2 = '15-6-7.8' ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&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_string3='14-8-16-46';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Raja.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 14:36:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750600#M236131</guid>
      <dc:creator>raja777pharma</dc:creator>
      <dc:date>2021-06-26T14:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Number in a string with special charctes in middle of number with regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750602#M236132</link>
      <description>&lt;P&gt;I would use a modified version of what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;proposed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input have $80.;
cards4;
Text charcters 1.2.34.16 text charcters many
15-6-7.8 text charcters many
text charctes words many 14-8-16-46 many alphabets
Regular number 12345 
;;;;;

data want;
 set have;
 pid=prxparse('/\d+[\d\.-]*\d+/');
 call prxsubstr(pid,have,p,l);
 if p&amp;gt;0 then want=substr(have,p,l);
 drop pid p l;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So this pattern:&lt;/P&gt;
&lt;PRE&gt;/\d+[\d\.-]*\d+/&lt;/PRE&gt;
&lt;P&gt;Says to match strings that start with a digit and end with a digit and have zero more more digits, periods or hyphens in between the two terminal digits.&amp;nbsp; So it will not match one digit strings.&lt;/P&gt;
&lt;PRE&gt;Obs    have                                                  want

 1     Text charcters 1.2.34.16 text charcters many          1.2.34.16
 2     15-6-7.8 text charcters many                          15-6-7.8
 3     text charctes words many 14-8-16-46 many alphabets    14-8-16-46
 4     Regular number 12345                                  12345
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;But it will match strings that are only digits.&amp;nbsp; If you need to eliminate those results you could test the string returned and make sure it has either a period or hyphen.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not indexc(want,'.-') then want=' ';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    have                                                     want

 1     Text charcters 1.2.34.16 text charcters many          1.2.34.16
 2     15-6-7.8 text charcters many                          15-6-7.8
 3     text charctes words many 14-8-16-46 many alphabets    14-8-16-46
 4     Regular number 12345

&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Jun 2021 15:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750602#M236132</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-26T15:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Number in a string with special charctes in middle of number with regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750606#M236133</link>
      <description>&lt;P&gt;Here's a tired old loop through a subset of characters in string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do string='listing16-88-004 . subjects of devations . xlsx'
           ,'listing 16.88.004. subjects of devations . xlsx';
    output;
  end;
run;

data want (drop=i);
  set have;
  length newvar $15;
  if anydigit(string) then do i=anydigit(string) to length(string);
    if anydigit(substr(string||' ',i,2)) then newvar=cats(newvar,char(string,i));
    else leave;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Starting at the first numeric character, it advances through &lt;EM&gt;&lt;STRONG&gt;string, a&lt;/STRONG&gt;&lt;/EM&gt;ppending the current character to &lt;EM&gt;&lt;STRONG&gt;newvar&lt;/STRONG&gt;&lt;/EM&gt; as long as the current character, or the next character (to accommodate current character as a separator), is numeric.&amp;nbsp; It doesn't care what the separator character is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once a non-qualifying character is reached, exit the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 16:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Number-in-a-string-with-special-charctes-in-middle-of/m-p/750606#M236133</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-26T16:34:13Z</dc:date>
    </item>
  </channel>
</rss>

