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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 482 views
  • 0 likes
  • 3 in conversation