BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RajeshPU
Calcite | Level 5

Hi,

Please help to me get "modified name" from "NAme". String length is varies

NameModifiedName
ABCDABCD
GHIJ0000GHIJ
RRJJZL0244RRJJZL
cdds_3cdds
ABSD0122ABSD
NNN0111NNN
ABCD0000ABCD
1 ACCEPTED SOLUTION

Accepted Solutions
shivas
Pyrite | Level 9

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

View solution in original post

6 REPLIES 6
Alpay
Fluorite | Level 6

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?

RajeshPU
Calcite | Level 5

Hi Alpay,

Yes. thats correct. i'm trying to keep only the characters

Thanks for simplifyng the question

shivas
Pyrite | Level 9

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

Keith
Obsidian | Level 7

You could simplify the compress function to keep just the letters A-Z,a-z, rather than remove non-letters.

modified = compress(name,,'ka');

Alpay
Fluorite | Level 6

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;

RajeshPU
Calcite | Level 5

Thank you Shiva, that works

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1646 views
  • 0 likes
  • 4 in conversation