help in extracting string

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

help in extracting string

Hi,

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

NameModifiedName
ABCDABCD
GHIJ0000GHIJ
RRJJZL0244RRJJZL
cdds_3cdds
ABSD0122ABSD
NNN0111NNN
ABCD0000ABCD

Accepted Solutions
Solution
‎07-04-2012 05:22 AM
Super Contributor
Posts: 349

Re: help in extracting string

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


All Replies
Frequent Contributor
Posts: 95

Re: help in extracting string

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?

New Contributor
Posts: 4

Re: help in extracting string

Hi Alpay,

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

Thanks for simplifyng the question

Solution
‎07-04-2012 05:22 AM
Super Contributor
Posts: 349

Re: help in extracting string

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

Regular Contributor
Posts: 151

Re: help in extracting string

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

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

Frequent Contributor
Posts: 95

Re: help in extracting string

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;

New Contributor
Posts: 4

Re: help in extracting string

Thank you Shiva, that works

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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