BookmarkSubscribeRSS Feed
littrellzj
Calcite | Level 5

Hello! I am trying to do a PROC SQL on two separate tables, however, I am missing a word within a variable so they cannot be merged. I need to add the text " County" exactly as shown to the end of my county variable, followed by ", Colorado". I tried CATX which added " Colorado" following a comma delimiter, but cannot add county. It must appear exactly as shown in the Goal example, with spaces included. Ideally, I'd like to concatenate my CT and county variable separated by a comma, and just add "County, Colorado" to the end, but the CATX function interrupts county and the text with another new comma. 

 

Goal: Census Tract 1, Chaffee County, Colorado

Output so far: Census Tract 1, Chaffee, Colorado

 

'Census Tract 1' comes from the CT variable, and 'Chaffee' comes from the county variable.

 

Code so far: 

CT_NEW = CATX(', ', CT, county, 'Colorado');
Run; 
 

I figured concatenating to be the best solution for this problem, but cannot seem to make it work. Thank you! 

1 REPLY 1
ballardw
Super User

Better is to provide examples of data, in this case from both data sets, and an example of the type of Join (sql does joins, not merges which in SAS is a bit different than any type of join) you are attempting.

 

You don't appear to show the starting value of any variable, just an incomplete output. You don't show the actual "county" or "ct" variables referenced. So it is pretty hard to tell what is going on.

I will say that I see no place that you attempt to use the literal value "county" adding to your string.

A guess would be

CT_NEW = CATX(', ', CT, county,'County, Colorado');

to add "County, Colorado" to every string.

or if you really think you need to add two different pieces to the same effect

CT_NEW = CATX(', ', CT, county, 'County', 'Colorado');

It is a good idea to post Code into a code or text box opened on the forum with the </> or "running man" icons that appear above the message window. This forum will reformat text pasted into the main message and has been known to result is some interesting things that won't run as a result. Also the boxes set code, or Log, apart from the discussion visually.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 386 views
  • 0 likes
  • 2 in conversation