how to trim to column and concatenate in PROC SQL?

Reply
Contributor
Posts: 39

how to trim to column and concatenate in PROC SQL?

PROC SQL;

  CREATE TABLE work.test

  AS SELECT DISTINCT TRIM(acct_ID) || "  " || TRIM(acct_num) AS CUST_ID

  FROM work.test_account

  ORDER BY CUST_ID;

  QUIT;

Basically i am trying to trim the account_id and account num and concatenate with a space in between them.

How can I do it through PROC sql?

Valued Guide
Posts: 858

Re: how to trim to column and concatenate in PROC SQL?

Here you go:

data have;

infile cards dsd dlm=',';

input one two;

cards;

500,600

200,100

;

run;

proc sql;

create table want as

select distinct *, cat(one,' ',two) as cust_id

from have;

Valued Guide
Posts: 858

Re: how to trim to column and concatenate in PROC SQL?

If it's all characters try this:

data have;

infile cards dsd dlm=',';

input one $ two $;

cards;

500  ,  600

200  ,  100

;

run;

proc sql;

create table want as

select distinct *, cat(strip(one),' ',strip(two)) as cust_id

from have;

Super Contributor
Posts: 275

Re: how to trim to column and concatenate in PROC SQL?

PROC SQL;

  CREATE TABLE work.test

  AS SELECT catx(' ',  DISTINCT acct_ID,acct_num) AS CUST_ID

  FROM work.test_account

  ORDER BY CUST_ID;

  QUIT;

Contributor
Posts: 39

Re: how to trim to column and concatenate in PROC SQL?

Thanks much...

Ask a Question
Discussion stats
  • 4 replies
  • 252 views
  • 3 likes
  • 3 in conversation