Hi,
Please help to me get "modified name" from "NAme". String length is varies
Name | ModifiedName |
ABCD | ABCD |
GHIJ0000 | GHIJ |
RRJJZL0244 | RRJJZL |
cdds_3 | cdds |
ABSD0122 | ABSD |
NNN0111 | NNN |
ABCD0000 | ABCD |
Hi Rajesh,
Try this..Hope it helps..
data have;
input name $ 20.;
modified = compress(name,'0123456789_');
cards;
ABCD
GHIJ0000
RRJJZL0244
cdds_3
ABSD0122
NNN0111
ABCD0000
;
run;
Thanks,
Shiva
Can you specify the rules (chars to keep/exclude)? e.g.: Are you trying to keep characters A to Z and a to z only?
Hi Alpay,
Yes. thats correct. i'm trying to keep only the characters
Thanks for simplifyng the question
Hi Rajesh,
Try this..Hope it helps..
data have;
input name $ 20.;
modified = compress(name,'0123456789_');
cards;
ABCD
GHIJ0000
RRJJZL0244
cdds_3
ABSD0122
NNN0111
ABCD0000
;
run;
Thanks,
Shiva
You could simplify the compress function to keep just the letters A-Z,a-z, rather than remove non-letters.
modified = compress(name,,'ka');
You may utilize regular expressions as well.
It will substitute null string for characters not in the range 'a' to 'z' (a-z) and 'A' to 'Z' (A-Z).
data x;
input Name $20.;
NewName = PRXCHANGE('s/[^a-zA-Z]//o',-1,Name);
datalines;
ABCD
GHIJ0000
RRJJZL0244
cdds_3
ABSD0122
NNN0111
ABCD0000
;
run;
Thank you Shiva, that works
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.