<?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 numeric values after indexing (with the indexed point being right of the values) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650931#M195229</link>
    <description>&lt;P&gt;Thank you so much! I've never seen this function before - it looks super useful!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry - would the ANYDIGIT also work if I have other digits in the cell too? Thank you again, I really appreciate your advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e.,&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Person&lt;/TD&gt;&lt;TD&gt;Description&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Bob&lt;/TD&gt;&lt;TD&gt;Bob walked 5 km at 10PM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Joe&lt;/TD&gt;&lt;TD&gt;Joe swan for 3.2 km yesterday&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 26 May 2020 22:01:54 GMT</pubDate>
    <dc:creator>JamieTee</dc:creator>
    <dc:date>2020-05-26T22:01:54Z</dc:date>
    <item>
      <title>How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650928#M195227</link>
      <description>&lt;P&gt;I have a variable 'description' that has something like 'bob walked 5 km' or 'joe swam for 3.2 km yesterday night'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to extract the values of '5' and '3.2' from this variable into a new variable, however, I'm stuck trying to figure out a way after i find the position of the "km" string. I haven't been able to find a way to read&amp;nbsp;&lt;EM&gt;left&lt;/EM&gt; of the indexed position. As a note, there is always a space before the "km"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Person&lt;/TD&gt;&lt;TD&gt;Description&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Bob&lt;/TD&gt;&lt;TD&gt;Bob walked 5 km at 10PM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Joe&lt;/TD&gt;&lt;TD&gt;Joe swan for 3.2 km yesterday&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I ideally want to create a table that looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Person&lt;/TD&gt;&lt;TD&gt;Description&lt;/TD&gt;&lt;TD&gt;Distance&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Bob&lt;/TD&gt;&lt;TD&gt;Bob walked 5 km at 10PM&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Joe&lt;/TD&gt;&lt;TD&gt;Joe swan for 3.2 km yesterday&lt;/TD&gt;&lt;TD&gt;3.2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 26 May 2020 22:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650928#M195227</guid>
      <dc:creator>JamieTee</dc:creator>
      <dc:date>2020-05-26T22:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650929#M195228</link>
      <description>&lt;P&gt;Use the ANYDIGIT function to find the first digit. Then use SCAN to find the next "word".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where = anydigit(description);
number = scan(substr(description,where),1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, this and just about any other manipulation requires an assumption or two, which you need to make sure is valid for the larger data set.&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 21:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650929#M195228</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-26T21:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650931#M195229</link>
      <description>&lt;P&gt;Thank you so much! I've never seen this function before - it looks super useful!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry - would the ANYDIGIT also work if I have other digits in the cell too? Thank you again, I really appreciate your advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e.,&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Person&lt;/TD&gt;&lt;TD&gt;Description&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Bob&lt;/TD&gt;&lt;TD&gt;Bob walked 5 km at 10PM&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Joe&lt;/TD&gt;&lt;TD&gt;Joe swan for 3.2 km yesterday&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 26 May 2020 22:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650931#M195229</guid>
      <dc:creator>JamieTee</dc:creator>
      <dc:date>2020-05-26T22:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650932#M195230</link>
      <description>&lt;P&gt;ANYDIGIT finds the location of the first digit in the string.&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 22:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650932#M195230</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-26T22:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650933#M195231</link>
      <description>&lt;P&gt;If you are specifically looking for digits preceding "km" and want to guard against extracting digits that appear way before "km", here is one way to do it.&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Not very elegant but seems to do the job. If you want functions to search backwards, use negative integers for the position.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data want ;
   set have ;
   distance = input(scan(substr(description,1,index(description,"km")-1),-1," "),best.) ;
run ;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 May 2020 22:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650933#M195231</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-26T22:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650935#M195232</link>
      <description>&lt;P&gt;This is the perfect solution thank you! What does the 'best' function do here?&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 22:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650935#M195232</guid>
      <dc:creator>JamieTee</dc:creator>
      <dc:date>2020-05-26T22:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650938#M195233</link>
      <description>BEST is used as the informat for the INPUT function. It is also a format when used in the PUT function.</description>
      <pubDate>Tue, 26 May 2020 22:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650938#M195233</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-26T22:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650942#M195234</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
 input Person $	Description	$30.;
 cards;
Bob	Bob walked 5 km at 10PM
Joe	Joe swan for 3.2 km yesterday
;
data want;
 set have;
 distance =scan(Description,findw(Description,'km',' ','ie')-1,' ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 May 2020 23:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650942#M195234</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-26T23:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650945#M195235</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input Person $	Description	$30.;
 cards;
Bob	Bob walked 5 km at 10PM
Joe	Joe swan for 3.2 km yesterday
;
data want;
 set have;
 distance=prxchange('s/(.*?)(\d+?\.?\d*?)(\skm)(.*)/$2/', -1, Description);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 May 2020 23:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/650945#M195235</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-26T23:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract numeric values after indexing (with the indexed point being right of the values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/651053#M195289</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input Person $	Description	$30.;
 cards;
Bob	Bob walked 5 km at 10PM
Joe	Joe swan for 3.2 km yesterday
;
data want;
 set have;
 pid=prxparse('/[\d\. ]+(?=km)/i');
 if pid then do;
  call prxsubstr(pid,Description,p,l);
  want=substr(Description,p,l);
 end;
 drop pid p l;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 May 2020 11:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-numeric-values-after-indexing-with-the-indexed/m-p/651053#M195289</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-27T11:59:47Z</dc:date>
    </item>
  </channel>
</rss>

