- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Experts,
i have a data like below in that i need to separate into words only clue we have is starting from the second Upper letter is next word.
for example if your take PraveenKumar i need to separate two words Praveen and Kumar.
Can anyone please help me how to separate the data into two words.
data wanted;
x='PraveenKumar';output;
x='RamSita';output;
x='JorgePaul';output;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can solve it by using regular expressions:
data want;
set wanted;
a = prxmatch('/[a-z][A-Z]/', x);
fname = substr(x,1,a);
lname = substr(x,a+1);
run;
Prxmatch looks for the first combination och lowcase character followed by an uppercase character 🙂
//Fredrik
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This solution trawls through the text and puts a space next to any capital letter (so if there are 3 it will turn into 3 words)
data have;
x='PraveenKumar';output;
x='RamSita';output;
x='JorgePaul';output;
run;
data want(drop = i letter);
set have;
attrib y length=$50;
y = "";
do i = 1 to length(x);
letter = substr(x,i,1);
if letter = upcase(letter) then y = catx(" ",y,letter);
else y = cats(y,letter);
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your quick response:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can solve it by using regular expressions:
data want;
set wanted;
a = prxmatch('/[a-z][A-Z]/', x);
fname = substr(x,1,a);
lname = substr(x,a+1);
run;
Prxmatch looks for the first combination och lowcase character followed by an uppercase character 🙂
//Fredrik
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
x='PraveenKumar';output;
x='RamSita';output;
x='JorgePaul';output;
run;
data want;
set have;
fname= char(compress(x,,'KU'),1);
lname= char(compress(x,,'KU'),2);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your code is incorrect. Needs tweaking. Char is not the function to use I am afraid
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
x='PraveenKumar';output;
x='RamSita';output;
x='JorgePaul';output;
run;
data want;
set have;
_iorc_=findc (x,,'U');
First_name=substr(x,_iorc_,findc (x,,'U', _iorc_ + 1)-_iorc_);
Last_name=substr(x,findc (x,,'U', _iorc_ + 1));
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And another one
data have;
x='PraveenKumar';output;
x='RamSita';output;
x='JorgePaul';output;
run;
data want;
set have;
First_name=substr(x,anyupper (x),anyupper (x,2)-1);
Last_name=substr(x,anyupper(x,2));
run;