## CAT, CATT, CATX, TRIM

Solved
Occasional Contributor
Posts: 19

# CAT, CATT, CATX, TRIM

I have 4 variables that I am trying to combine into one but each thing I try is not giving me the result I want.  Here are my entries 20,1,6312468,1 and I want to combine them to get 2016312468 but every time I try something I get 20 space 1 space 6312468 space 1.  I have tried cat, catt, catx and trim each one then use !! to combine and each time it returns the spaces.  Any thoughts?

Accepted Solutions
Solution
‎09-22-2011 09:51 AM
PROC Star
Posts: 8,163

## CAT, CATT, CATX, TRIM

Use strip rather than trim.  E.g.,

data have;

w=20;

x=1;

y=6312468;

z=1;

want=cat(strip(w),

strip(x),

strip(y),

strip(z));

run;

All Replies
Regular Contributor
Posts: 166

## CAT, CATT, CATX, TRIM

would compress keeping your numeric values not work?

compress(column,'0123456789','k')

Solution
‎09-22-2011 09:51 AM
PROC Star
Posts: 8,163

## CAT, CATT, CATX, TRIM

Use strip rather than trim.  E.g.,

data have;

w=20;

x=1;

y=6312468;

z=1;

want=cat(strip(w),

strip(x),

strip(y),

strip(z));

run;

Occasional Contributor
Posts: 19

## CAT, CATT, CATX, TRIM

Both of these work thanks for the fast response!

Posts: 3,852

Valued Guide
Posts: 2,191

## CAT, CATT, CATX, TRIM

data_null_; is providing the correct answer, because CATS() performs the STRIP() and the concatenation

e.g.

want = cats( of w x y z  );

(not even those commas needed when the list is preceeded with OF )

PROC Star
Posts: 8,163

## CAT, CATT, CATX, TRIM

Peter, Of course data_null_ is correct .. as he virtually always is!  However, the other responses were also correct.  For the fun of it I ran a one trial test on 1 million identical records.  I stopped at one test as I happened to like the results: my proposed method came in first (cpu: 1.01 seconds), data_null_'s second (cpu: 1.04 seconds), and your suggestion third (cpu: 1.14 seconds).  Of course, on repeated tests, I would guess that any of the methods could come in at any position.  Your and datanull's methods are definitely easier to type and I'd gladly award both of you correct answers if I could, but it wasn't my post.

🔒 This topic is solved and locked.