<?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 extract continous numbers in text string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623590#M183614</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean by continuous number ?&lt;/P&gt;
&lt;P&gt;Do you mean extract all digits?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set datain;
	name_d = compress(name,,"dK");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 10 Feb 2020 15:53:06 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-02-10T15:53:06Z</dc:date>
    <item>
      <title>How extract continous numbers in text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623589#M183613</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a challenging question.&amp;nbsp; I have dataset shown below.&amp;nbsp; I would like to&amp;nbsp;extract the&amp;nbsp;continuous numbers from&amp;nbsp;all kinds of different text formats.&amp;nbsp; In&amp;nbsp;the end, I need the numbers without any&amp;nbsp;spaces and lines.&amp;nbsp; &amp;nbsp;I am wondering if there is&amp;nbsp;a way to do that.&amp;nbsp; Thank you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data datain;

format name $ 500.;

input name &amp;amp;;

cards;

CAR ID 5648MA

0009463

000-4721

  6325IL

PAUL__0065

0435KK-GGGG 1

;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the following is results I am looking for:&lt;/P&gt;
&lt;P&gt;5648,&lt;/P&gt;
&lt;P&gt;0009463,&lt;/P&gt;
&lt;P&gt;0004721,&lt;/P&gt;
&lt;P&gt;6325,&lt;/P&gt;
&lt;P&gt;0065,&lt;/P&gt;
&lt;P&gt;0435.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 15:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623589#M183613</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-10T15:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: How extract continous numbers in text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623590#M183614</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean by continuous number ?&lt;/P&gt;
&lt;P&gt;Do you mean extract all digits?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set datain;
	name_d = compress(name,,"dK");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Feb 2020 15:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623590#M183614</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-10T15:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: How extract continous numbers in text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623592#M183616</link>
      <description>&lt;P&gt;Please provide what you want out from each of those example values.&amp;nbsp; Do you want to create a number from each string?&amp;nbsp; multiple numbers?&amp;nbsp; What if there are more than 15 digits in a row such that SAS cannot store it as a number?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 15:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623592#M183616</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-10T15:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: How extract continous numbers in text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623594#M183618</link>
      <description>&lt;P&gt;It seems like didn't apply for the last one.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 15:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623594#M183618</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-10T15:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: How extract continous numbers in text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623600#M183621</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set datain;
	name_d  = prxchange('s/\b\d\b//',-1,prxchange('s/[^\d\s]//',-1,name));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture d’écran 2020-02-10 à 17.03.07.png" style="width: 145px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35977i123607B8DB3D74E3/image-size/small?v=v2&amp;amp;px=200" role="button" title="Capture d’écran 2020-02-10 à 17.03.07.png" alt="Capture d’écran 2020-02-10 à 17.03.07.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623600#M183621</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-10T16:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: How extract continous numbers in text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623612#M183628</link>
      <description>&lt;P&gt;Not recommending nor ideal, but good and fun to experiment&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data datain;

format name $ 500.;

input name &amp;amp;;

cards;
CAR ID 5648MA
0009463
000-4721
  6325IL
PAUL__0065
0435KK-GGGG 1
;

data want;
	set datain;
	_n_ = countw(name,'-','kd');
	length want $10;
	do _n_=1 to _n_;
	 want=compress(scan(name,_n_,'-','kd'),,'kd');
	 if length(want)&amp;gt;1 then output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Feb 2020 16:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623612#M183628</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-02-10T16:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: How extract continous numbers in text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623660#M183645</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a modified version of the function provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;. I modified your input to test it with more complicated input including several occurrences of single-digit or multi-digit groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data datain;
infile cards truncover;
input name $char100.;
cards;
CAR ID 5648MA
0009463
000-4721
1  6325IL 34 2 
PAUL__0065
1 2 3 45 abc
0435KK-GGGG 1
12
test_1_4_ 9 more
;
run;

data want; set datain;
	length num $100;
	num = compress(prxchange('s/\b\d\b//',-1,prxchange('s/[^\d]/ /',-1,name)));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="num.gif" style="width: 314px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35981i98A6F2ADC3500089/image-size/large?v=v2&amp;amp;px=999" role="button" title="num.gif" alt="num.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 18:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-extract-continous-numbers-in-text-string/m-p/623660#M183645</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2020-02-10T18:54:36Z</dc:date>
    </item>
  </channel>
</rss>

