<?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 a number from a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691383#M210421</link>
    <description>&lt;P&gt;This also worked....thank you very much!&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2020 20:17:52 GMT</pubDate>
    <dc:creator>Xinxin</dc:creator>
    <dc:date>2020-10-13T20:17:52Z</dc:date>
    <item>
      <title>Extract a number from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691357#M210410</link>
      <description>&lt;P&gt;I have data as shown below. I need to add the numbers preceding "mL"&amp;nbsp; for each ID, into 1 variable, and add the numbers preceding&amp;nbsp;mL/kg per ID into another variable.&lt;/P&gt;
&lt;P&gt;I tried removing the spaces but I don't know how many digits the number will be, to count back.&lt;/P&gt;
&lt;P&gt;I tried extracting the numeric part but then other numbers like the 9 from the % also gets extracted.&lt;/P&gt;
&lt;P&gt;Any help on how to do it in SAS (or Excel) will be appreciated. Thank you!&lt;/P&gt;
&lt;TABLE width="359"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;ID&lt;/TD&gt;
&lt;TD width="295"&gt;DISPLAY_NAME&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 2,250 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 1,000 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 1,000 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 500 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 1,000 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 250 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 1,551 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;lactated ringers bolus 1,000 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 1,000 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;PLASMA-LYTE A bolus 1,000 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 30 mL/kg/dose&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;sodium chloride 0.9 % bolus 1,000 mL&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 13 Oct 2020 18:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691357#M210410</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2020-10-13T18:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a number from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691364#M210415</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/237"&gt;@Xinxin&lt;/a&gt;&amp;nbsp; There are probably easier ways, but here's one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input id name $50.;
    datalines;
1 sodium chloride 0.9 % bolus 2,250 mL
1 sodium chloride 0.9 % bolus 1,000 mL
1 sodium chloride 0.9 % bolus 1,000 mL
2 sodium chloride 0.9 % bolus 500 mL
3 sodium chloride 0.9 % bolus 1,000 mL
3 sodium chloride 0.9 % bolus 250 mL
3 sodium chloride 0.9 % bolus 1,551 mL
4 lactated ringers bolus 1,000 mL
4 sodium chloride 0.9 % bolus 1,000 mL
4 PLASMA-LYTE A bolus 1,000 mL
5 sodium chloride 0.9 % bolus 30 mL/kg/dose
5 sodium chloride 0.9 % bolus 1,000 mL
    ;
run;

data want;
    set have;
    reverse_name = upcase(strip(reverse(name)));
    mL = index(reverse_name, 'LM');
    space = find(reverse_name, ' ', mL + 3);
    difference = space - (mL + 3);
    numbers = input(reverse(substr(reverse_name, mL + 3, difference)), comma12.);
    keep id name numbers;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mklangley_0-1602613869656.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50633i81CCF743A139C20F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mklangley_0-1602613869656.png" alt="mklangley_0-1602613869656.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The code above assumes the desired number is always preceded by a space (" ") and followed by a space and mL (i.e. " mL").&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Also, this puts all those numbers into a single variable. Did you need the mL/kg/dose number in a separate variable? It might be easier to have the &lt;STRONG&gt;number&lt;/STRONG&gt; in one column, and then have another column for the &lt;STRONG&gt;units&lt;/STRONG&gt; (e.g. mL or mL/kg/dose).&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 18:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691364#M210415</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-10-13T18:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a number from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691365#M210416</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    c=max(index(upcase(disp), 'ML/KG'), index(upcase(disp),'ML'));
    if c then res=input(compress(scan(substr(disp,1,c-1),-1, ' '),,'kd'),best.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Oct 2020 18:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691365#M210416</guid>
      <dc:creator>vellad</dc:creator>
      <dc:date>2020-10-13T18:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a number from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691375#M210417</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;

/*Regex Pattern*/
/*(?&amp;lt;=bolus\s)(.*)(?=\smL)*/
/*Positive Lookbehind (?&amp;lt;=bolus\s) - Assert that the Regex below matches bolus matches the characters bolus literally*/
/*\s matches any whitespace character */
/*1st Capturing Group (.*)*/
/*.* matches any character (except for line terminators)*/
/*Positive Lookahead (?=\smL) - Assert that the Regex below matches*/
/*\s matches any whitespace character (equal to [\r\n\t\f\v ])*/
/*mL matches the characters mL literally (case sensitive)*/
	pat_id=prxparse('/(?&amp;lt;=bolus\s)(.*)(?=\smL)/');
	call prxsubstr(pat_id,name,pos,len);
	num_=input(substr(name,pos,len),comma8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Oct 2020 19:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691375#M210417</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-10-13T19:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a number from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691382#M210420</link>
      <description>Interesting way to solve it...it worked ...Thank you!&lt;BR /&gt;</description>
      <pubDate>Tue, 13 Oct 2020 20:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691382#M210420</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2020-10-13T20:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a number from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691383#M210421</link>
      <description>&lt;P&gt;This also worked....thank you very much!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 20:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-number-from-a-string/m-p/691383#M210421</guid>
      <dc:creator>Xinxin</dc:creator>
      <dc:date>2020-10-13T20:17:52Z</dc:date>
    </item>
  </channel>
</rss>

