<?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 to extract a number in a specific format out of a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634344#M188266</link>
    <description>&lt;P&gt;Depending on the exact requirement, another option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  LINE="Send email to  reference, Mailbox..*        Email Subject Line - reference Follow-Up....Body of email (complete template below).... ....student Name.... James GENEVIEVE...Student Phone #.... 12345712457 best, 5458712458....reference #.... 012000222.1.... .... ONFIDENTIALITY NOTICE..This communication may contain privileged or confidential information. If you are not the intended recipient or received this communication by error, please notify the sender and delete the message without copying or disclosing it. Thank you..... .... ..";
  STR=prxchange('s/'           %* substitution requested;
              ||'.*'           %* match anything;
              ||'reference #'  %* then reference space hash;
              ||'[^\d]*'       %* then more optional text except digits ;
              ||'(\d+\.?\d*)'  %* then digits including an optional embedded dot &amp;lt;= capture this;
              ||'.*'           %* then the rest of the string;
              ||'/\1'          %* replace all with captured group ;
              ||'/',1,LINE);
  putlog STR=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;STR=012000222.1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Mar 2020 05:55:33 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-03-24T05:55:33Z</dc:date>
    <item>
      <title>How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634325#M188264</link>
      <description>&lt;P&gt;Hi SAS Experts i have below string and i am trying to extract the number that is in the following highlighted format, the issue is the format is not consistent but i would like to extract anything after "reference # " just till the numbers as shown below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;string:&lt;/P&gt;&lt;P&gt;“Send email to&amp;nbsp; reference, Mailbox..*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Email Subject Line - reference Follow-Up....Body of email (complete template below).... ....student Name.... James GENEVIEVE...Student Phone #.... 12345712457 best, 5458712458....reference #.... &lt;EM&gt;&lt;U&gt;012000222.1&lt;/U&gt;&lt;/EM&gt;.... .... ONFIDENTIALITY NOTICE..This communication may contain privileged or confidential information. If you are not the intended recipient or received this communication by error, please notify the sender and delete the message without copying or disclosing it. Thank you..... .... .."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;desired output:&lt;/P&gt;&lt;P&gt;"012000221.1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in advance, thank you for your effort.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 02:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634325#M188264</guid>
      <dc:creator>PrudhviB</dc:creator>
      <dc:date>2020-03-24T02:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634335#M188265</link>
      <description>&lt;P&gt;A regular expression could help. What exactly will work depends on the details/variations in your actual data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  length string $2000;
  retain string;
  input;
  string=catx(' ',string,_infile_);
  if _n_=10 then output;
datalines;
Send email to  reference, Mailbox..*        
Email Subject Line - reference Follow-Up....
Body of email (complete template below).... ....
student Name.... James GENEVIEVE...Student Phone #.... 
12345712457 best, 5458712458....reference #.... 012000222.1.... .... 
ONFIDENTIALITY NOTICE..This communication may contain privileged or 
confidential information. If you are not the intended recipient or 
received this communication by error, please notify the sender 
and delete the message without copying or disclosing it. 
Thank you..... .... ..
;

data want;
  set have;
  length want_str $32;
  _prxid=prxparse('/reference #[^#\d]*(\d+\.?\d*)/oi');
  if prxmatch(_prxid,trim(string))&amp;gt;0 then 
    want_str=prxposn(_prxid,1,trim(string));
run;

proc print data=want;
  var want_str;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 03:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634335#M188265</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-24T03:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634344#M188266</link>
      <description>&lt;P&gt;Depending on the exact requirement, another option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  LINE="Send email to  reference, Mailbox..*        Email Subject Line - reference Follow-Up....Body of email (complete template below).... ....student Name.... James GENEVIEVE...Student Phone #.... 12345712457 best, 5458712458....reference #.... 012000222.1.... .... ONFIDENTIALITY NOTICE..This communication may contain privileged or confidential information. If you are not the intended recipient or received this communication by error, please notify the sender and delete the message without copying or disclosing it. Thank you..... .... ..";
  STR=prxchange('s/'           %* substitution requested;
              ||'.*'           %* match anything;
              ||'reference #'  %* then reference space hash;
              ||'[^\d]*'       %* then more optional text except digits ;
              ||'(\d+\.?\d*)'  %* then digits including an optional embedded dot &amp;lt;= capture this;
              ||'.*'           %* then the rest of the string;
              ||'/\1'          %* replace all with captured group ;
              ||'/',1,LINE);
  putlog STR=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;STR=012000222.1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 05:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634344#M188266</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-24T05:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634349#M188269</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using prxchange() is what I've done first as well but then realized that you'll end up with the source string if there is no match.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 06:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634349#M188269</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-24T06:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634388#M188272</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; True&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if STR=LINE then STR=' ';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Not saying this is better. Just another option. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;RegEx are expensive, I prefer to use them just once if possible.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 09:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634388#M188272</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-24T09:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634404#M188279</link>
      <description>Doesn’t prxposn() just retrieve the capture buffer without parsing the source string again?</description>
      <pubDate>Tue, 24 Mar 2020 11:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634404#M188279</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-24T11:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634552#M188342</link>
      <description>Just Amazing this worked like charm and not only that i learn something new with your detailed explanation &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&lt;BR /&gt;if there is a reference page where i can get to learn this please do share.</description>
      <pubDate>Tue, 24 Mar 2020 20:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634552#M188342</guid>
      <dc:creator>PrudhviB</dc:creator>
      <dc:date>2020-03-24T20:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634640#M188372</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; Doesn’t prxposn() just retrieve the capture buffer without parsing the source string again?&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;You are right. Your solution is actually more efficient. I never used to use this function but I'll keep in mind now.&lt;/P&gt;
&lt;P&gt;Thanks for the heads up. &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;</description>
      <pubDate>Wed, 25 Mar 2020 07:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634640#M188372</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-25T07:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a number in a specific format out of a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634641#M188373</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; a reference page&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;This syntax is called a regular expression and there a tons of didactic resources online. That's how I learnt. &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;</description>
      <pubDate>Wed, 25 Mar 2020 07:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-number-in-a-specific-format-out-of-a-string/m-p/634641#M188373</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-25T07:31:58Z</dc:date>
    </item>
  </channel>
</rss>

