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

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

 

1 ACCEPTED SOLUTION
5 REPLIES 5
mkeintz
PROC Star

proc sql;

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

quit;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SKP
Calcite | Level 5 SKP
Calcite | Level 5

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

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

hmoghul
Fluorite | Level 6

Hi,

Suppose you got this dataset and want to combine two columns :

 

data ddd;

input ID var1 $ var2 $;

cards;

1 a . 

2 . b

3 . c

4 d .

5 e . 

;

run;

proc sql;

select coalesce(var1,var2) as combine_var

from ddd;

quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 60862 views
  • 1 like
  • 5 in conversation