Hello
I am trying to add a period for a name column only when the name shows up as one letter.
data have;
middle_name;
datalines
M
Tim
Bob
I
Tina
I tried to do this:
data want;
set have;
if length(strip(middle_name)) = 1 then
middle_name = catx('.', middle_name, 1, 1), substr(middle_nm,1));
run;
but the middle initials show as M.M and I.I
Any help would be greatly appreciated! Definitely am a beginner.
if length(strip(middle_name)) = 1 and not missing(middle_name) then
middle_name = cats( middle_name,'.');
Try
if length(strip(middle_name)) = 1 then
middle_name = cats( middle_name,'.');
CATX only places the character BETWEEN things. The CATS will append the period (or other string) and you have already checked that you only want to do that when there is only one character
if length(strip(middle_name)) = 1 and not missing(middle_name) then
middle_name = cats( middle_name,'.');
Thank you so much! That worked.
Cheers!
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.