I have a table that has two numeric values called year and month. I would like to create a new table that has one value called ym which is just the concatenation of year and month. Here is an example:

proc sql; create table test as select CONCAT(year, month) as ym from tbl; run; 

What is the CONCAT function that goes there?

2 Answers

CAT, CATS, CATT, CATX all perform concatenation, as long as you're on 9.1.3 or later (and CATQ on 9.2 or later); CAT does basic concatenation, CATS concatenates and strips spaces, CATT trims, and CATX concatenates with a delimiter.

Typically CATS is the correct function to use for numbers, since by default numbers are put into a format with spaces (BEST12., so "3 " is 3).

proc sql; create table test as select CATS(year, month) as ym from tbl; run; 
1

As another option, you can concatenate with the || operator like X1||X2 or even multiples at once like X1||X2||X3||X4

You can add trim or left like TRIM(LEFT(X1))||TRIM(LEFT(X2))

You can add delimeters like TRIM(X1)||','||TRIM(X2)

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.