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

Hello SAS Communities, 

 

I am looking to change an Initials variable into the form of FML and if there is no middle initial F-L. 

The current initials variable is in the form F.M.L and when there is no middle initial it looks like this F. L.

 

The output I have

 

 

The output I want is

Inits

RWP

NAE

TCJ

FLY

GSC

S-R

etc

 

Here is what I have so far

 

DATA WORK.data ;
SET import.records (RENAME=(Inits = initials ID=social ZipCode=ZipCd));


Inits

inits2 = COMPRESS(initials, '.');
IF length(inits2) = 2 THEN Inits = CATX('-', CHAR(inits2, 1), CHAR(inits2, 2));
ELSE Inits= inits2;

 


RUN;

 

This does not work because those with missing middle initials get outputted as just their first initial, ie S. R. is just S.

 

Thank you! 

  

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

When you apply the COMPRESS function you remove the dots only. You need to remove blanks as well in order to get a length of 2. So the second parameter to COMPRESS should be:

inits2 = COMPRESS(initials, ' .');

That will get S. R. to come out as SR.  WIthout that change, you are getting S R.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

When you apply the COMPRESS function you remove the dots only. You need to remove blanks as well in order to get a length of 2. So the second parameter to COMPRESS should be:

inits2 = COMPRESS(initials, ' .');

That will get S. R. to come out as SR.  WIthout that change, you are getting S R.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 590 views
  • 0 likes
  • 3 in conversation