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;
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.
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.
Thank you so much!!
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'
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!