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

Hi everyone,

I have a data set in excel that has Owner City, Owner state, and owner zip in separate columns. I needed to combine these 3 columns into one with a comma separating owner city from owner state and then a space in between owner state and owner zip. Here is the code I have. SAS has correctly combined all columns into 1, which is named combined. Owner city is separated from owner state with a comma, but owner state is not separated from owner zip. This is an example of what is coming back to me.  Augusta, GA30909. 

I need it to look like Augusta, GA 30909. Thank you to anyone willing to help!!

data aik.props_new1;
set aik.props_news;
combined= cats(Owner_City, ' , ' Owner_State, '  ' , Owner_Zip);
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data a;
    owner_city='Auburn';
    owner_state='GA';
    owner_zip=12345;
    combined=cat(trim(left(Owner_City)), ', ',trim(left(owner_state)), ' ' , trim(left(Owner_Zip)));
run;

 

You can't use CATS for this because CATS will eliminate text strings that are all blanks, which is what you are seeing.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
data a;
    owner_city='Auburn';
    owner_state='GA';
    owner_zip=12345;
    combined=cat(trim(left(Owner_City)), ', ',trim(left(owner_state)), ' ' , trim(left(Owner_Zip)));
run;

 

You can't use CATS for this because CATS will eliminate text strings that are all blanks, which is what you are seeing.

--
Paige Miller
jwint12
Calcite | Level 5

Thank you so much!!

Tom
Super User Tom
Super User

Use CATX() if you want to insert delimiters between strings.

combined= catx(' ',catx(', ',Owner_City, Owner_State), Owner_Zip);

The problem with CATS() is the S which means STRIP(), so it throws away the space.  The CATX() function will also strip the values, but not the delimiter sting.  So you can create:

New York, NY 10001

from 'New York[,'NY', and '10061'