data split_names;
input name $25;
datalines;
JohnDoe
SrinivasPavan
KishoreKumar
ChandrasekaRao
;
run;
fHi Experts,
In the above code i want split names every second capital letter without regex solution please
output
________
John Doe
Srinivas Pavan
Kishore Kumar
Chandrasekar Rao
Just use some other tool to find the location of the second uppercase letter.
Such as the VERIFY() function.
NOTE: remember to include the period in the format specification, or else your input statement will just read the single byte from column 25.
data split_names;
input name $25.;
datalines;
JohnDoe
SrinivasPavan
KishoreKumar
ChandrasekaRao
Ghandi
;
data want;
set split_names;
loc = verify(substr(name,2),'abcdefghijklmnopqrstuvwzy');
if loc then last=substr(name,loc+1);
first=substr(name,1,length(name)-lengthn(last));
run;
proc print;
var name loc first last;
run;
Obs name loc first last 1 JohnDoe 4 John Doe 2 SrinivasPavan 8 Srinivas Pavan 3 KishoreKumar 7 Kishore Kumar 4 ChandrasekaRao 11 Chandraseka Rao 5 Ghandi 6 Ghandi
Just use some other tool to find the location of the second uppercase letter.
Such as the VERIFY() function.
NOTE: remember to include the period in the format specification, or else your input statement will just read the single byte from column 25.
data split_names;
input name $25.;
datalines;
JohnDoe
SrinivasPavan
KishoreKumar
ChandrasekaRao
Ghandi
;
data want;
set split_names;
loc = verify(substr(name,2),'abcdefghijklmnopqrstuvwzy');
if loc then last=substr(name,loc+1);
first=substr(name,1,length(name)-lengthn(last));
run;
proc print;
var name loc first last;
run;
Obs name loc first last 1 JohnDoe 4 John Doe 2 SrinivasPavan 8 Srinivas Pavan 3 KishoreKumar 7 Kishore Kumar 4 ChandrasekaRao 11 Chandraseka Rao 5 Ghandi 6 Ghandi
Here is an example that adds another case with a middle name.
data split_names;
input name $25.;
datalines;
JohnDoe
SrinivasPavan
KishoreKumar
ChandrasekaRao
Ghandi
MaryJoeSmith
;
run;
data new;
set split_names;
len=length(name);
ucount = countc(name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'U'); /* count the number of uppercase letters */
next=anyupper(substr(name,2));
upper=anyupper(name,-len); /* position of last uppercase letter */
if next=0 then first=name;
else first=substr(name,1,next);
if ucount=2 then last=substr(name,next+1);
else if ucount=3 then do;
middle=substr(name,next+1,len-upper-1);
last=substr(name,upper);
end;
run;
proc print data=new;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.