Help using Base SAS procedures

to combine 2 character columns into one new column

Reply
Contributor SKP
Contributor
Posts: 25

to combine 2 character columns into one new column

hi,

 

I have 2 character columns in a table, and am tring to combine the 2 columns into new column, like I can concatenate in excel.

How can i combine the 2 with SQL query?

 

Thanks,

SKP

 

Valued Guide
Posts: 797

Re: to combine 2 character columns into one new column

proc sql;

 create table want as select *,  cats(col1,col2) as new_column from have;

quit;

Contributor SKP
Contributor
Posts: 25

Re: to combine 2 character columns into one new column

Thank you for your reply.  I've tried your query, the new column was added and it's blank, even col1 and col2 show some characters.  what could be a reason why this returns blank?

 

Also, if I want to have space or underscore between col1 and col2, how can I adjust cats formula?

 

Thanks,

SKP

 

Super User
Posts: 17,837

Re: to combine 2 character columns into one new column

Look at CATX instead then. 

 

The list of SAS functions and short descriptions can be found here:

http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0w6napahk6...

Super User
Super User
Posts: 7,401

Re: to combine 2 character columns into one new column

We have no way of telling.  You have not provided any test data, example output, logs etc. to make any kind of judgement.  If you want good answers then post good questions.  Post example test data, in the form of a datastep, which highlights your question.  If you have some code or example output, then provide that as well. 

 

As per the manual, cats, catx, catt, cat, || are all concatentation functions - you can find more information in the manual on each.  They can be used in proc SQL - as long as it is not pass-through SQL - and should work perfectly well.

Ask a Question
Discussion stats
  • 4 replies
  • 403 views
  • 0 likes
  • 4 in conversation