<?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 the numbers before a certain type of strings in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/553081#M9312</link>
    <description>&lt;P&gt;I would use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if not prxId then prxId + prxParse("/(\d*(\.\d*)?)\s?U/");
set have;
if prxMatch(prxId, Unit) then
    num = input(prxPosn(prxId, 1, Unit), best.);
format num best.;
drop prxId;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note :&lt;/P&gt;
&lt;P&gt;The pattern (UNIT|UN|U) will match anything that starts with U, so you might as well match only U. However, listing all alternatives explicitly would be useful if you needed to extract the unit word in question with something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;unitWord = prxPosn(prxId, 2, Unit);&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Apr 2019 22:23:19 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-04-22T22:23:19Z</dc:date>
    <item>
      <title>Extract the numbers before a certain type of strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/553046#M9302</link>
      <description>&lt;P&gt;Hello SAS experts,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to extract numbers before a certain type of strings? I am working on a project to extract the numbers in front of the word UNITS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My variable, unit, has all types of variations. Here is the example,&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Unit&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; &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; &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; &amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10 UNITS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4 UNITS FOR ACCU=259,VERIFY BY ATHENA R&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F.S 199 30 UNITS PER ORDERS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0 UNITS/FSBS 144&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.25ML/125UNITS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.35ML/175 UNITS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1.5 UNITS DOUBLE CHECKED&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10 U8NITS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10UNITS-BS=306&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;10 U8NITS&lt;/P&gt;&lt;P&gt;10UNITS-BS=306&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to get (variable named num_wanted) is&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Unit&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; &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; &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; &amp;nbsp;&lt;/TD&gt;&lt;TD&gt;num_wanted&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10 UNITS&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4 UNITS FOR ACCU=259,VERIFY BY ATHENA R&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F.S 199 30 UNITS PER ORDERS&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0 UNITS/FSBS 144&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.25ML/125UNITS&lt;/TD&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.35ML/175 UNITS&lt;/TD&gt;&lt;TD&gt;175&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1.5 UNITS DOUBLE CHECKED&lt;/TD&gt;&lt;TD&gt;1.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10 U8NITS&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10UNITS-BS=306&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried multiple ways but I couldn't figure how to extract the number before a certain type of string (UNITS have lots of variations such as U, UNIT, UN, UMIT, etc).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you help me out? THank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 20:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/553046#M9302</guid>
      <dc:creator>BochengJing</dc:creator>
      <dc:date>2019-04-22T20:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the numbers before a certain type of strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/553074#M9310</link>
      <description>&lt;P&gt;There are several ways to do this. I think this accommodates your needs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Unit:$100.;
infile datalines dlm='|';
datalines; 
10 UNITS
4 UNITS FOR ACCU=259,VERIFY BY ATHENA R
F.S 199 30 UNITS PER ORDERS
0 UNITS/FSBS 144
0.25ML/125UNITS
0.35ML/175 UNITS
1.5 UNITS DOUBLE CHECKED
10 U8NITS
10UNITS-BS=306
10 U8NITS
10UNITS-BS=306
;

data want(keep=Unit num);
   set have;
   RegExID=prxparse('/(\d\.*\d*)\s*(UNITS|U8NITS|UNIT|UMIT|UN|U)/i');
   position=prxmatch(RegExID, Unit);
   num=input(prxposn(RegExID, 1, Unit), best8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code gives you the below. Let me know if it works on your real data &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&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;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture.PNG" style="width: 513px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28926i611624E034A31B03/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 21:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/553074#M9310</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-04-22T21:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the numbers before a certain type of strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/553081#M9312</link>
      <description>&lt;P&gt;I would use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if not prxId then prxId + prxParse("/(\d*(\.\d*)?)\s?U/");
set have;
if prxMatch(prxId, Unit) then
    num = input(prxPosn(prxId, 1, Unit), best.);
format num best.;
drop prxId;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note :&lt;/P&gt;
&lt;P&gt;The pattern (UNIT|UN|U) will match anything that starts with U, so you might as well match only U. However, listing all alternatives explicitly would be useful if you needed to extract the unit word in question with something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;unitWord = prxPosn(prxId, 2, Unit);&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 22:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/553081#M9312</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-22T22:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the numbers before a certain type of strings</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/554009#M9433</link>
      <description>&lt;P&gt;Thank you for your solution. It was wonderful. I never knew how to use the Perl Syntax before and thanks for showing me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2019 15:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-the-numbers-before-a-certain-type-of-strings/m-p/554009#M9433</guid>
      <dc:creator>BochengJing</dc:creator>
      <dc:date>2019-04-25T15:58:57Z</dc:date>
    </item>
  </channel>
</rss>

