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

I'm trying to concatenate firstname, middlename, lastname, and professionaltitle columns to look like this:

 

John David Smith, MD

 

However when I try the below cat function within my PROC SQL statement, I get a column that is completely blank with null values:

 

cat(PROVIDER_FIRST_NAME, " ", PROVIDER_MIDDLE_NAME, " ", PROVIDER_LAST_NAME, ", ", PROF_DESIGNATION) as provider_name

 

The CATT, CATS, and CATX functions return values as expected but I'm stumped as to why the CAT function returns nothing.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@InspectahDex wrote:

 

The CATT, CATS, and CATX functions return values as expected but I'm stumped as to why the CAT function returns nothing.


The other functions trim (remove blank spaces) by default and CAT does not. 

 

Does this work for you:

cat(trim(PROVIDER_FIRST_NAME), " ", trim(PROVIDER_MIDDLE_NAME), " ", trim(PROVIDER_LAST_NAME), ", ", trim(PROF_DESIGNATION)) as provider_name

 


@InspectahDex wrote:

I'm trying to concatenate firstname, middlename, lastname, and professionaltitle columns to look like this:

 

John David Smith, MD

 

However when I try the below cat function within my PROC SQL statement, I get a column that is completely blank with null values:

 

cat(PROVIDER_FIRST_NAME, " ", PROVIDER_MIDDLE_NAME, " ", PROVIDER_LAST_NAME, ", ", PROF_DESIGNATION) as provider_name

 

The CATT, CATS, and CATX functions return values as expected but I'm stumped as to why the CAT function returns nothing.


 

 

View solution in original post

6 REPLIES 6
Reeza
Super User

@InspectahDex wrote:

 

The CATT, CATS, and CATX functions return values as expected but I'm stumped as to why the CAT function returns nothing.


The other functions trim (remove blank spaces) by default and CAT does not. 

 

Does this work for you:

cat(trim(PROVIDER_FIRST_NAME), " ", trim(PROVIDER_MIDDLE_NAME), " ", trim(PROVIDER_LAST_NAME), ", ", trim(PROF_DESIGNATION)) as provider_name

 


@InspectahDex wrote:

I'm trying to concatenate firstname, middlename, lastname, and professionaltitle columns to look like this:

 

John David Smith, MD

 

However when I try the below cat function within my PROC SQL statement, I get a column that is completely blank with null values:

 

cat(PROVIDER_FIRST_NAME, " ", PROVIDER_MIDDLE_NAME, " ", PROVIDER_LAST_NAME, ", ", PROF_DESIGNATION) as provider_name

 

The CATT, CATS, and CATX functions return values as expected but I'm stumped as to why the CAT function returns nothing.


 

 

InspectahDex
Obsidian | Level 7
It does but another issue is popping up. When the provider has no middle name, there are 3 spaces instead of 1 because of that rule. Is there anyway to account to have a single space for instances where a middle name value is null?
InspectahDex
Obsidian | Level 7
I found a solution to that second issue. I just added compbl before the (cat(trim... and it worked! Thanks, Reeza!
ChrisNZ
Tourmaline | Level 20

CAT() does this (assuming the variable lengths here):

'John                                                                 ' || 
'David ' ||
'Smith ' ||
', ' ||
'MD '       

which does not fit in your result variable.
If PROVIDER_FIRST_NAME is empty, you may well run out of space to see anything at all.

 

 

Tom
Super User Tom
Super User

Hard to tell without seeing the context you are using this.

But the CAT() function is inappropriate for what you are doing.

You will not get 

John David Smith, MD

as the result unless PROVIDER_FIRST_NAME is defined as length $4 and PROVIDER_MIDDLE_NAME is defined as length $5 and PROVIDER_LAST_NAME is defined as length $5 and PROF_DESIGNATION is defined as length equal to longer than $2.

 

That is because the CAT() function, unlike the other functions you mentioned, does NOT trim the trailing spaces from the fixed length character strings that SAS uses.

InspectahDex
Obsidian | Level 7
Ahh, thanks for putting it that way. That makes sense!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 2859 views
  • 5 likes
  • 4 in conversation