<?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: regular expression in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48960#M10122</link>
    <description>Thanks Guys!</description>
    <pubDate>Thu, 25 Jun 2009 20:36:17 GMT</pubDate>
    <dc:creator>SASPhile</dc:creator>
    <dc:date>2009-06-25T20:36:17Z</dc:date>
    <item>
      <title>regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48956#M10118</link>
      <description>10MG/2ML&lt;BR /&gt;
5MG/ML&lt;BR /&gt;
12MG KIT&lt;BR /&gt;
0.4MG&lt;BR /&gt;
24MG KIT&lt;BR /&gt;
5MG&lt;BR /&gt;
0.6MG&lt;BR /&gt;
10MG/2ML&lt;BR /&gt;
5MGFLEX&lt;BR /&gt;
10MG&lt;BR /&gt;
&lt;BR /&gt;
for the above data is used the following reg expression:&lt;BR /&gt;
&lt;BR /&gt;
if  _N_ = 1 then  RE = PRXPARSE ("/ \d{1,5}\.?\d{0,4}\?mg/i");&lt;BR /&gt;
retain  RE;&lt;BR /&gt;
call PRXSUBSTR(RE,Drug_Strength_Name,START,LENGTH);&lt;BR /&gt;
if START GT 0 then  do;&lt;BR /&gt;
 str  = SUBSTRN(Drug_Strength_Name,START+1 ,LENGTH-1 );&lt;BR /&gt;
 output;&lt;BR /&gt;
 end;&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
it dosent return any values at all.</description>
      <pubDate>Thu, 25 Jun 2009 18:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48956#M10118</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-06-25T18:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48957#M10119</link>
      <description>Suggest you add some SAS diagnostic statements ("nn" increments for easier correlation in code to log):&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG '&amp;gt;DIAGnn ' _all_;&lt;BR /&gt;
&lt;BR /&gt;
Hopefully this additional info will help you diagnose the problem systematically.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 25 Jun 2009 18:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48957#M10119</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-25T18:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48958#M10120</link>
      <description>This program works for the data set you posted:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
retain re;&lt;BR /&gt;
infile datalines;&lt;BR /&gt;
input Drug_Strength_Name $ 1-9;&lt;BR /&gt;
&lt;BR /&gt;
if _N_ = 1 then &lt;BR /&gt;
   re = prxparse("/\d+(\.\d+)?MG((\/\dML)| KIT|FLEX)?/i");&lt;BR /&gt;
call prxsubstr(re,Drug_Strength_Name, start, length);&lt;BR /&gt;
if start gt 0 then do;&lt;BR /&gt;
   str = substrn(Drug_Strength_Name, start, length);&lt;BR /&gt;
   put str;&lt;BR /&gt;
end;&lt;BR /&gt;
datalines;&lt;BR /&gt;
10MG/2ML&lt;BR /&gt;
5MG/ML&lt;BR /&gt;
12MG KIT&lt;BR /&gt;
0.4MG&lt;BR /&gt;
24MG KIT&lt;BR /&gt;
5MG&lt;BR /&gt;
0.6MG&lt;BR /&gt;
10MG/2ML&lt;BR /&gt;
5MGFLEX&lt;BR /&gt;
10MG&lt;BR /&gt;
;;;;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Log:&lt;BR /&gt;
[pre]&lt;BR /&gt;
704  data _null_;&lt;BR /&gt;
705  retain re;&lt;BR /&gt;
706  infile datalines;&lt;BR /&gt;
707  input Drug_Strength_Name $ 1-9;&lt;BR /&gt;
708&lt;BR /&gt;
709  if _N_ = 1 then&lt;BR /&gt;
710     re = prxparse("/\d+(\.\d+)?MG((\/\dML)| KIT|FLEX)?/i");&lt;BR /&gt;
711  call prxsubstr(re,Drug_Strength_Name, start, length);&lt;BR /&gt;
712  if start gt 0 then do;&lt;BR /&gt;
713     str = substrn(Drug_Strength_Name, start, length);&lt;BR /&gt;
714     put str;&lt;BR /&gt;
715  end;&lt;BR /&gt;
716  datalines;&lt;BR /&gt;
&lt;BR /&gt;
10MG/2ML&lt;BR /&gt;
5MG&lt;BR /&gt;
12MG KIT&lt;BR /&gt;
0.4MG&lt;BR /&gt;
24MG KIT&lt;BR /&gt;
5MG&lt;BR /&gt;
0.6MG&lt;BR /&gt;
10MG/2ML&lt;BR /&gt;
5MGFLEX&lt;BR /&gt;
10MG&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.01 seconds&lt;BR /&gt;
      cpu time            0.01 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
727  ;;;;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 25 Jun 2009 18:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48958#M10120</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2009-06-25T18:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48959#M10121</link>
      <description>Hi SASPhile,&lt;BR /&gt;
Tim@SAS gave the perfect regular expression. &lt;BR /&gt;
I came up with re = PRXPARSE ("/[0-9]+(\.[0-9]*)?MG(\/[0-9]*ML| KIT|FLEX)?/i");&lt;BR /&gt;
I realized its similar to what Tim@SAS  posted &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;  .&lt;BR /&gt;
&lt;BR /&gt;
Just to add more to the logic and regular expression. Whenever u are trying to create a regular expression try and break down the pattern. In your case of provided data &lt;BR /&gt;
1) Integer part hence [0-9]+   &amp;lt;--- i come from perl background hence used to [0-9] instead of \d, don't mind.&lt;BR /&gt;
2) Decimal part(may or may not come hence optional) hence (\.[0-9]*)?&lt;BR /&gt;
3) MG is just after the integer or decimal part (always coming) hence MG&lt;BR /&gt;
4) (An Integer may or may not come with ML) or ( KIT may come with leading space) or (FLEX would come) ....as any of the three cases can happen or may not happen at all (e.g 10MG) hence above 3 cases are optional hence regular expression for this part would be ----&amp;gt; (\/[0-9]*ML| KIT|FLEX)?&lt;BR /&gt;
&lt;BR /&gt;
Now going back to the original regular expression that you coded &lt;BR /&gt;
RE = PRXPARSE ("/ \d{1,5}\.?\d{0,4}\?mg/i") . For the datalines written by Tim@SAS, your regular expression would not work. The reasons are :&lt;BR /&gt;
1) PRXPARSE ("/ \d     ..if you look closely, there is a space regulare expression is looking for before the integer. Maybe your data has that space, not sure thats why im pointing it out.&lt;BR /&gt;
2) d{0,4}\? would match in case of 0.4?MG and not 0.4MG hence it should have been like d{0,4}?&lt;BR /&gt;
Even after fixing the above 2 things you would only get Integer + decimal + MG being pattern matched (e.g. 10.4MG , 10MG &amp;amp; 0.4MG ) the KITS/2ML/ML etc would still not get matched. For that check out the regular expression posted by me or Tim@SAS &lt;BR /&gt;
&lt;BR /&gt;
Njoy understanding the patterns!!!!!!!!!! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 25 Jun 2009 20:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48959#M10121</guid>
      <dc:creator>SushilNayak</dc:creator>
      <dc:date>2009-06-25T20:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48960#M10122</link>
      <description>Thanks Guys!</description>
      <pubDate>Thu, 25 Jun 2009 20:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48960#M10122</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-06-25T20:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: regular expression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48961#M10123</link>
      <description>Actually I missed one: 5MG/ML. The RE needs to accept a slash followed by 0 or more digits followed by ML: "\/\d*ML". Here's the corrected version:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
retain re;&lt;BR /&gt;
infile datalines;&lt;BR /&gt;
input Drug_Strength_Name $ 1-9;&lt;BR /&gt;
&lt;BR /&gt;
if _N_ = 1 then &lt;BR /&gt;
   re = prxparse("/\d+(\.\d+)?MG((\/\d*ML)| KIT|FLEX)?/i");&lt;BR /&gt;
call prxsubstr(re,Drug_Strength_Name, start, length);&lt;BR /&gt;
if start gt 0 then do;&lt;BR /&gt;
   str = substrn(Drug_Strength_Name, start, length);&lt;BR /&gt;
   put str;&lt;BR /&gt;
end;&lt;BR /&gt;
datalines;&lt;BR /&gt;
10MG/2ML&lt;BR /&gt;
5MG/ML&lt;BR /&gt;
12MG KIT&lt;BR /&gt;
0.4MG&lt;BR /&gt;
24MG KIT&lt;BR /&gt;
5MG&lt;BR /&gt;
0.6MG&lt;BR /&gt;
10MG/2ML&lt;BR /&gt;
5MGFLEX&lt;BR /&gt;
10MG&lt;BR /&gt;
;;;;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 26 Jun 2009 11:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/regular-expression/m-p/48961#M10123</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2009-06-26T11:56:57Z</dc:date>
    </item>
  </channel>
</rss>

