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 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 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.
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.
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.
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!
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.