06-20-2017 08:19 AM - edited 06-20-2017 08:29 AM
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 must be
06-20-2017 08:30 AM - edited 06-20-2017 08:31 AM
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.
last_ initials name K. Jansen J.L. deVries G.J.P.G. Boersma
06-20-2017 08:52 AM
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 ;