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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;
Kurt_Bremser
Super User

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;

 


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1003 views
  • 2 likes
  • 3 in conversation