BookmarkSubscribeRSS Feed
draroda
Fluorite | Level 6

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 ?

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16
Data have;
set want;
character=compress(values,,ka);
numeric=compress(values,,kd);
run;

Thanks,
Jag
Steelers_In_DC
Barite | Level 11

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 732 views
  • 1 like
  • 3 in conversation