Hi, I have names in my table that have the first and last name format. I need to convert the format to first initial follow by dot then last name.
For example, Sandy Chint would be S.Chint, Kathy Kumarxy would be K.Kumarxy, and Thomas P Magliu would be T.Magliu
These names have first and last name format, as well as middle name/initial between first and last name. How to do this in prxchange or is there a better way to do it? Below is some examples. Thanks.
data ReversedNames;
input name $32.;
datalines;
Sandy Chint
Kathy Kumarxy
Bobby Smith
Jason McDonald
Annie Avor
Thomas P Magliu
Joan Smith Korcos
;
run;
How about
data ReversedNames;
input name $32.;
datalines;
Sandy Chint
Kathy Kumarxy
Bobby Smith
Jason McDonald
Annie Avor
Thomas P Magliu
Joan Smith Korcos
;
run;
data want;
set ReversedNames;
newname = cat(char(name, 1), '. ', scan(name, -1));
run;
How about
data ReversedNames;
input name $32.;
datalines;
Sandy Chint
Kathy Kumarxy
Bobby Smith
Jason McDonald
Annie Avor
Thomas P Magliu
Joan Smith Korcos
;
run;
data want;
set ReversedNames;
newname = cat(char(name, 1), '. ', scan(name, -1));
run;
I prefer the common string functions for this rather simple task:
data want;
set reversednames;
name = catx(".",substr(name,1,1),scan(name,-1));
run;
@LL5 wrote:
Hi, I have names in my table that have the first and last name format. I need to convert the format to first initial follow by dot then last name.
For example, Sandy Chint would be S.Chint, Kathy Kumarxy would be K.Kumarxy, and Thomas P Magliu would be T.Magliu
These names have first and last name format, as well as middle name/initial between first and last name. How to do this in prxchange or is there a better way to do it? Below is some examples. Thanks.data ReversedNames; input name $32.; datalines; Sandy Chint Kathy Kumarxy Bobby Smith Jason McDonald Annie Avor Thomas P Magliu Joan Smith Korcos ; 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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.