<?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 numbers from a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330473#M74146</link>
    <description>&lt;P&gt;Try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  txt = 'xxxx 12345999 mm-mm/m 24/08/2015 08:30';
  new = compress(txt, ,'A');
  put new=;
  n=countw(new);
  if n &amp;gt; 0 then do;
     do i=1 to n;
        word = scan(new,i);
        len=lengthn(word);
        if indexc(word,'.,/:;$') =0 and /* add any other special character, like pound */
           input(word,?? 8.) ne . and len=8
        then output;
  end; end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Feb 2017 14:32:42 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-02-07T14:32:42Z</dc:date>
    <item>
      <title>Extract numbers from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330142#M73997</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS chracter variable and I want to extract a specific 8 digits from it that could appear at any point in time. The string may also include dates in the format dd/mm/yyyy so the variable is not just simply 8 digits and loads of characters. Is there anyway of extracting 8 consecutive digits from this string?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of the variable string below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;aaaaaaaaaaaaaa 12/01/2016 bbbbbbbbbbb &lt;STRONG&gt;12345678&lt;/STRONG&gt; nnnnnnn&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;23456789&lt;/STRONG&gt; aaaaaaaaaaaaaa bbbbbbbbbbbb&lt;/P&gt;&lt;P&gt;01/12/2016aaaaaaaaabbbbb&lt;STRONG&gt;12345678&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 11:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330142#M73997</guid>
      <dc:creator>mk131190</dc:creator>
      <dc:date>2017-02-06T11:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330143#M73998</link>
      <description>&lt;P&gt;Are the digits restricted to being&amp;nbsp;&lt;STRONG&gt;12345678 and&amp;nbsp;23456789&amp;nbsp;&lt;/STRONG&gt;or could it also be 54839572 eg?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 11:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330143#M73998</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-06T11:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330156#M73999</link>
      <description>&lt;P&gt;Adapt next example code to your needs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
  txt = 'xxxx 897453266 mmmmm 24/08/2015 bbb';
  new = compress(txt, ,'A');  /* remove alphabetic characters */
  put new=;
  n=countw(new);
  if n &amp;gt; 0 then do;
     do i=1 to n;
        word = scan(new,i);
        len=lengthn(word);
        if input(word,?? 8.) ne .
        then put word= len=;
  end; end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Feb 2017 12:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330156#M73999</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-06T12:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330158#M74000</link>
      <description>you can use also index(word,'/') = 0 to eliminate dates, but is there other special characters ?&lt;BR /&gt;like dots, comma, etc.</description>
      <pubDate>Mon, 06 Feb 2017 12:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330158#M74000</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-06T12:20:59Z</dc:date>
    </item>
    <item>
      <title>Betreff: Extract numbers from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330160#M74001</link>
      <description>&lt;P&gt;Use prxmatch + prxposn if there is just one number to extract.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
   set work.have;
   
   length rx number 8;
   retain rx;
   drop rx;

   if _n_= 1 then do;
      rx = prxparse('/.*(\d{8,8}).*/');
   end;

   if prxmatch(rx, string) then do;
      number = input(prxposn(rx, 1, string), 8.);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Feb 2017 12:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330160#M74001</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-02-06T12:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330431#M74126</link>
      <description>&lt;P&gt;It could be any 8 digit number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 09:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330431#M74126</guid>
      <dc:creator>mk131190</dc:creator>
      <dc:date>2017-02-07T09:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330432#M74127</link>
      <description>&lt;P&gt;There are also pound values and colons for datetime.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 09:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330432#M74127</guid>
      <dc:creator>mk131190</dc:creator>
      <dc:date>2017-02-07T09:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330473#M74146</link>
      <description>&lt;P&gt;Try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  txt = 'xxxx 12345999 mm-mm/m 24/08/2015 08:30';
  new = compress(txt, ,'A');
  put new=;
  n=countw(new);
  if n &amp;gt; 0 then do;
     do i=1 to n;
        word = scan(new,i);
        len=lengthn(word);
        if indexc(word,'.,/:;$') =0 and /* add any other special character, like pound */
           input(word,?? 8.) ne . and len=8
        then output;
  end; end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2017 14:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numbers-from-a-string/m-p/330473#M74146</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-07T14:32:42Z</dc:date>
    </item>
  </channel>
</rss>

