DATA Step, Macro, Functions and more

Address Concatenation

Occasional Contributor
Posts: 10

Address Concatenation

Hi there


I have separate adrress fields like Address, City, State and Zipcode but I would like to create a single address fields by combining all these four fields into one field like : 1345 Quail Creek Ln, Alexandria, VA 22039


Address                              City                           State               Zipcode

1345 Quail Creek Ln           Alexandria                VA                  22039

4569 Foxhole Drive            Chantilly                    VA                  22033


Single address field I want to create is: 1345 Quail Creek Ln, Alexandria, VA 22039

                                                               4569 Foxhole Drive, Chantilly, VA 22033


I tried using CATX function like this

New_address = catx(',',Address,City,State,Zipcode); but it resolves into: 1345 Quail Creek LN,Alexandria,VA,22039

How do I insert space between two elements of the address separated by comma and just the space between state and ziocode as I have shown above ? Please help me. Thanks


Super User
Posts: 17,819

Re: Address Concatenation

Put a space in the first parameter.


this_works = catx(", ", "first", "second");
put this_works;
Occasional Contributor
Posts: 10

Re: Address Concatenation

Thank you Ballardw. That wroks.

Super User
Posts: 10,500

Re: Address Concatenation


New_address = catx(',',Address,City,catx(' ',State,Zipcode));

so the State and Zipcode are combined first with a space and thus treated as a single string by the outer CATX. For a somewhat older appearance you could use multiple spaces such as

catx('   ',State,Zipcode)

to have the zipcode a bit further from the state

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation