DATA Step, Macro, Functions and more

Extracting character and numeric values in different variables

Reply
Contributor
Posts: 34

Extracting character and numeric values in different variables

Dear All,

 

Please help in below.

 

Values                        Character        Numeric

ABC123                       ABC                123

12AB45                         AB                  1245

12345A                            A                  12345

A12D52                            AD               1252

123456                                                  123456

 

Can you please guide on how can i extract numeric and character in different ?

Trusted Advisor
Posts: 1,137

Re: Extracting character and numeric values in different variables

Data have;
set want;
character=compress(values,,ka);
numeric=compress(values,,kd);
run;

Thanks,
Jag
Valued Guide
Posts: 860

Re: Extracting character and numeric values in different variables

Here is a solution:

 

data have;
input values$;
cards;
ABC123
12AB45
12345A
A12D52
123456
;

data want;
set have;
NUMERIC = prxchange("s/[^0-9]//",-1,values);
CHARACTERS = prxchange("s/[^A-Z]//",-1,values);
NUMBERS = input(prxchange("s/[^0-9]//",-1,values),8.);
run;

Ask a Question
Discussion stats
  • 2 replies
  • 165 views
  • 1 like
  • 3 in conversation