<?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 specific text string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788782#M252291</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
      infile datalines delimiter='#';
  input Comments : $200.  ;
datalines;
	UGESTAGE=34 5/7 WKS #
	UPREM, UGESTAGE = 32WKS #
	UGESTAGE  =33.4 WKS #
	GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU
;
run;

data Want;
      infile datalines delimiter='/';
  input UGESTAGE  ;
datalines;
	34 /
	32 /
	33 /
	
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I use Chrome, all the function icons are shown again.&amp;nbsp; I think the previous IE was too old.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jan 2022 03:32:00 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2022-01-07T03:32:00Z</dc:date>
    <item>
      <title>Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788735#M252261</link>
      <description>Hello,
I would like to extract numbers after text 'UGESTAGE'.  Please advice, thank you.   BTW, I haven't visited the community for a while, why I couldn't use the insert SAS code function.  I apologize if the codes are not shown properly below.  

data Have;
      infile datalines delimiter='#';
  input Comments : $200.  ;
datalines;
	UGESTAGE=34 5/7 WKS #
	UPREM, UGESTAGE = 32WKS #
	UGESTAGE  =33.4 WKS #
	GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU
;
run;

data Want;
      infile datalines delimiter='/';
  input UGESTAGE  ;
datalines;
	34 /
	32 /
	33 /
	
;
run;</description>
      <pubDate>Thu, 06 Jan 2022 20:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788735#M252261</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-01-06T20:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788742#M252267</link>
      <description>&lt;P&gt;You should be able to post program code in either a text box or code box opened by clicking on the &amp;lt;&amp;gt; or "running man" icons that appear above the message window (7th and 8th from left to right).&lt;/P&gt;
&lt;P&gt;It is possible this is what you meant/wanted to post. Is the first data step correct? or should there be 3 lines of USESTAGE=?&lt;/P&gt;
&lt;PRE&gt;data Have;
 infile datalines delimiter='#';
 input Comments : $200. ;
 datalines;
 UGESTAGE=34 5/7 WKS # UPREM, UGESTAGE = 32WKS # UGESTAGE =33.4 WKS # GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU 
;
 run;
 data Want;
 infile datalines delimiter='/';
 input UGESTAGE ;
 datalines;
 34 / 32 / 33 / 
;
 run;
 &lt;/PRE&gt;
&lt;P&gt;Are you sure that Want data set contains what you really want? It only has the value of 34 for one record.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 21:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788742#M252267</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-06T21:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788745#M252270</link>
      <description>&lt;P&gt;I'm really not good at all with RegEx but I would like to be. This may work with some of your data until you have a different pattern that breaks it.&amp;nbsp; But maybe it will get you started.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data extracted;
	set have;
	pattern = prxparse ("/(?&amp;lt;=[=|= ])\d\d(\.[0-9]{1,2})?/");
	call prxsubstr (pattern, comments, start, length);
		if start gt 0 then do;
			ugestage = substr(comments, start, length);
			output;
		end;
	keep ugestage;
run;

proc print data =  extracted;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;gives me&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;BR /&gt;
&lt;TABLE class="table" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt; &lt;COL class="rowheader" /&gt; &lt;COL class="data" /&gt; &lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="header" scope="colgroup"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="colgroup"&gt;ugestage&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;34&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;2&lt;/TD&gt;
&lt;TD class="b data"&gt;32&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="b rowheader"&gt;3&lt;/TD&gt;
&lt;TD class="b data"&gt;
&lt;P&gt;33.4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Edit:&amp;nbsp; Ballard's question about 33.4 is very important.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I updated the RegEx to return 33.4&lt;/DIV&gt;</description>
      <pubDate>Thu, 06 Jan 2022 23:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788745#M252270</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2022-01-06T23:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788776#M252287</link>
      <description>&lt;DATA have=""&gt;&lt;/DATA&gt;</description>
      <pubDate>Fri, 07 Jan 2022 03:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788776#M252287</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-01-07T03:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788777#M252288</link>
      <description>Sorry, I don't see any &amp;lt;&amp;gt; or 'running man' icon.</description>
      <pubDate>Fri, 07 Jan 2022 03:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788777#M252288</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-01-07T03:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788780#M252289</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1641525419962.png" style="width: 593px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67174i1A277829A778F637/image-dimensions/593x246?v=v2" width="593" height="246" role="button" title="Patrick_1-1641525419962.png" alt="Patrick_1-1641525419962.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 03:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788780#M252289</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-01-07T03:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788782#M252291</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
      infile datalines delimiter='#';
  input Comments : $200.  ;
datalines;
	UGESTAGE=34 5/7 WKS #
	UPREM, UGESTAGE = 32WKS #
	UGESTAGE  =33.4 WKS #
	GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU
;
run;

data Want;
      infile datalines delimiter='/';
  input UGESTAGE  ;
datalines;
	34 /
	32 /
	33 /
	
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I use Chrome, all the function icons are shown again.&amp;nbsp; I think the previous IE was too old.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 03:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788782#M252291</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-01-07T03:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788794#M252299</link>
      <description>&lt;P&gt;Do your example strings really start with four leading spaces like you have in your lines of in-line data?&lt;/P&gt;
&lt;P&gt;If so your input statement that is using the normal $ informat will remove those leading spaces.&amp;nbsp; To preserve the leading spaces you need to read the lines using $CHAR.&amp;nbsp; Or copy the values from the _INFILE_ automatic variable after executing the INPUT statement.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 04:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788794#M252299</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-07T04:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Numbers from specific text string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788827#M252323</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
 infile datalines delimiter='#';
 input  @'UGESTAGE' temp : $200. @@ ;
 UGESTAGE=scan(temp,1,'.','kd');
 datalines;
	UGESTAGE=34 5/7 WKS #
	UPREM, UGESTAGE = 32WKS #
	UGESTAGE  =33.4 WKS #
	GASTROJEJUNOSTOMY DEPENDENCE, BILATERAL GRADE 4 VU
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jan 2022 12:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-Numbers-from-specific-text-string/m-p/788827#M252323</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-01-07T12:00:22Z</dc:date>
    </item>
  </channel>
</rss>

