Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concat two numbers in sas proc sql

Tags:

sas

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?

like image 226
Alex Avatar asked Apr 24 '13 15:04

Alex


People also ask

How do I concatenate two numbers in SAS?

You can also use the (older) method of the SAS concatenation operator (||) to combine values.

How do I concatenate in SQL SAS?

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 .

How do you append data in PROC SQL?

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.

What is CATX function in SAS?

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.


1 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;
like image 183
Joe Avatar answered Nov 01 '22 17:11

Joe