<?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 numeric value from character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652693#M195990</link>
    <description>&lt;P&gt;COMPRESS() with the 'kd' option to keep digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

want = input(compress(variable, , 'kd'), 8.);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to extract numeric value from the data below. Please suggest. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed;&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;50&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $1-13;
datalines;
1
1+
2
2+
10
4
4+
normal
50
abnormal
many negative
5&amp;lt;
;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jun 2020 22:01:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-06-02T22:01:16Z</dc:date>
    <item>
      <title>How to extract a numeric value from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652688#M195988</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to extract numeric value from the data below. Please suggest. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed;&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;50&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $1-13;
datalines;
1
1+
2
2+
10
4
4+
normal
50
abnormal
many negative
5&amp;lt;
;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 21:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652688#M195988</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-06-02T21:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a numeric value from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652693#M195990</link>
      <description>&lt;P&gt;COMPRESS() with the 'kd' option to keep digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

want = input(compress(variable, , 'kd'), 8.);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to extract numeric value from the data below. Please suggest. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed;&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;50&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $1-13;
datalines;
1
1+
2
2+
10
4
4+
normal
50
abnormal
many negative
5&amp;lt;
;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 22:01:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652693#M195990</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-02T22:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a numeric value from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652725#M196008</link>
      <description>&lt;P&gt;Alternatively, you can use perl regular expressions as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input a $1-13;
datalines;
1
1+
2
2+
10
4
4+
normal
50
abnormal
many negative
5&amp;lt;
;


data want;
set one;
want=prxchange('s/\D//oi',-1,a);
if want ne '';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jun 2020 03:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652725#M196008</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-03T03:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a numeric value from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652758#M196018</link>
      <description>&lt;P&gt;I would use the COMPRESS function to get rid of the "&amp;lt;", and then use the TRAILSGN (trailing sign) informat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set one;
  n=input(compress(a,"&amp;lt;"),?? trailsgn.);
  if not missing(n);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "??" suppresses log warnings about invalid values.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 05:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652758#M196018</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-06-03T05:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a numeric value from character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652763#M196021</link>
      <description>&lt;P&gt;Here a way using an Informat with a Regular Expression. I've also included the values with no digits in it in case you also want to convert these to some number. If not then simply remove these values from the informat and add a selection to your data step like: &lt;BR /&gt;&lt;EM&gt;if missing(want_var) then delete;&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue toDigits(default=20 upcase) 
    'NORMAL'        = 100
    'ABNORMAL'      = 101
    'MANY NEGATIVE' = 102
    's/\D*(\d+)\D*/$1/' (regexpe) = _same_ 
    other=_same_
    ;
run;

/* use the informat to directly read the data (want_var1)
   or to convert a string from another variable (want_var2)
*/
data sample;
  input have_var $1-13 @1 want_var1 toDigits.;
  want_var2=input(have_var,toDigits.);
  datalines;
1
1+
2
2+
10
4
4+
normal
50
abnormal
many negative
5&amp;lt;
;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1591166623442.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40311i7A597D055A51352B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1591166623442.png" alt="Patrick_1-1591166623442.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 07:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-numeric-value-from-character-variable/m-p/652763#M196021</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-03T07:32:28Z</dc:date>
    </item>
  </channel>
</rss>

