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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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