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?
You can also use the (older) method of the SAS concatenation operator (||) to combine values.
Example: Concatenate Using PROC SQLproc sql; create table combined as /* 1*/ select * from animal /* 2*/ outer union corresponding /* 3*/ select * from plant; /* 4*/ quit; Use the Create statement to create the table, combined . Include all variables from animal .
The output of PROC SQL is same as the output of previous example. proc append base=dataset1 data=dataset2; run; If you want to append data and store it to another dataset, you can run PROC APPEND twice to do it.
The CATX function returns a value to a variable, or returns a value in a temporary buffer. The value that is returned from the CATX function can be up to 32767 characters, except in WHERE clauses.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With