Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract Numeric Value using SAS

Tags:

sas

My raw data is in the form

Var
12 A+
14 A+
AB+ 19
AB:20
20
25
27 New

I want to extract the numeric portion of it only.

Can anybody please help me how to process this data in sas.

Thank you in advance. Rgds.

like image 296
Beta Avatar asked Dec 30 '25 20:12

Beta


2 Answers

You could use the COMPRESS function, which takes the form

COMPRESS(<source><, chars><, modifiers>)

Update: There are many ways to achieve this. As per their comments, RWill and Keith provide the best solutions:

var2=input(compress(var,compress(var,,"d")),best.);

or even better:

var2=input(compress(var,,"kd"),best.);
like image 79
DavB Avatar answered Jan 02 '26 06:01

DavB


Just as @itzy mentioned above, Perl regular expression will do with ease:

  var2=prxchange("s/[^0-9]//",-1,var);

This will remove all non-numerical characters. In this statement, 's/' begins a string, [^0-9] means all non-numerical characters. -1 defines an until-end match.

like image 33
Robbie Liu Avatar answered Jan 02 '26 05:01

Robbie Liu