<?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 numeric parts from a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404254#M98265</link>
    <description>&lt;P&gt;That code will show notes in the log, when the second word has letters.&amp;nbsp; To prevent those notes in the log, you can test to see if there are any letters in the second word before converting it to a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if anyalpha(scan(char_string,2,' '))=0 then
    middle_number=input(scan(char_string,2,' '),12.);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 14 Oct 2017 22:49:38 GMT</pubDate>
    <dc:creator>SuzanneDorinski</dc:creator>
    <dc:date>2017-10-14T22:49:38Z</dc:date>
    <item>
      <title>Extract numeric parts from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404247#M98261</link>
      <description>&lt;P&gt;I have a character variable that takes on the following values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A 111 C111&lt;/P&gt;&lt;P&gt;AB 1234 D311&lt;/P&gt;&lt;P&gt;A/B AA A1212&lt;/P&gt;&lt;P&gt;BC 123 D123&lt;/P&gt;&lt;P&gt;CSA JJK P00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to grab the number between the first and second space, if that part is indeed a number. I would like to get:&lt;/P&gt;&lt;P&gt;111&lt;/P&gt;&lt;P&gt;1234&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;123&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve this? Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Oct 2017 21:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404247#M98261</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-10-14T21:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric parts from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404250#M98262</link>
      <description>&lt;P&gt;You can use the scan function to find the second word, when a blank space is the delimiter between words.&amp;nbsp; Use the input function to convert that second word to a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length char_string $ 25;
  input char_string $25. ;
  datalines;
A 111 C111
AB 1234 D311
A/B AA A1212
BC 123 D123
CSA JJK P00
  ;
run;

proc print data=have;
run;

data want;
  set have;
  middle_number=input(scan(char_string,2,' '),12.);
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Oct 2017 22:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404250#M98262</guid>
      <dc:creator>SuzanneDorinski</dc:creator>
      <dc:date>2017-10-14T22:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric parts from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404254#M98265</link>
      <description>&lt;P&gt;That code will show notes in the log, when the second word has letters.&amp;nbsp; To prevent those notes in the log, you can test to see if there are any letters in the second word before converting it to a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if anyalpha(scan(char_string,2,' '))=0 then
    middle_number=input(scan(char_string,2,' '),12.);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Oct 2017 22:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404254#M98265</guid>
      <dc:creator>SuzanneDorinski</dc:creator>
      <dc:date>2017-10-14T22:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric parts from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404258#M98266</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12496"&gt;@SuzanneDorinski&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Another way to suppress these warnings: Use the&amp;nbsp;&lt;EM&gt;??&lt;/EM&gt; argument with the input function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  middle_number=input(scan(char_string,2,' '),?? best32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Oct 2017 00:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404258#M98266</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-15T00:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric parts from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404470#M98321</link>
      <description>Works well. Thank you!</description>
      <pubDate>Mon, 16 Oct 2017 14:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-parts-from-a-string/m-p/404470#M98321</guid>
      <dc:creator>apolitical</dc:creator>
      <dc:date>2017-10-16T14:43:14Z</dc:date>
    </item>
  </channel>
</rss>

