BookmarkSubscribeRSS Feed
Gerrit65
Calcite | Level 5

I need to produce a SAS-dataset in which the initials of the client have to be splitted by dots.

 

Input SAS dataset

 

Output SAS dataset must be like this

     

Initials

Last_name

 

Initials must be

Last_name

K

Jansen

 

K.

Jansen

JL

de Vries

 

J.L.

de Vries

GJPG

Boersma

 

G.J.P.G.

Boersma

4 REPLIES 4
kiranv_
Rhodochrosite | Level 12

please show sample input data and output data you want to have . Many of us will not open attachments for various issues like virus etc.

Kurt_Bremser
Super User
data have;
input initials :$5. last_name :$20.;
cards;
K Jansen
JL deVries
GJPG Boersma
;
run;

data want;
length initials $10;
set have (rename=(initials=_initials));
do i = 1 to length(_initials);
  initials = trim(initials) !! substr(_initials,i,1) !! '.';
end;
drop i _initials;
run;

proc print data=want noobs;
run;

Note the way I presented example data in a data step for easy recreation (needs only copy/paste and run).

Also note how I took care of the increasing length of the initials variable.

The result:

             last_
initials     name

K.          Jansen 
J.L.        deVries
G.J.P.G.    Boersma

 

Gerrit65
Calcite | Level 5
Thanks Kurt!! It works excellent!!!
Haikuo
Onyx | Level 15

PRX seems handy:

 

data have;
infile cards truncover ;
input var $ 100.;
newvar=prxchange('s/(\w)/$1./',-1,var);
cards;
K
Jansen
JL
de Vries
JPG
Boersma
;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 777 views
  • 2 likes
  • 4 in conversation