I have data set X that can have variable number of columns named c1, c2, c3 etc cn.
I need to concatenate them in one string. I need to have code that works regardless what the number of those columns is.
Is there a way to concatenate with some c: wildcard or similat to that?
Tom,
how about:
data have;
input id (c1-c5)($);
cards;
1 a b c d e
2 d r b t t
;
data want;
length newvar $ 50;
set have;
newvar=catt(of c:);
proc print;run;
Obs newvar id c1 c2 c3 c4 c5
1 abcde 1 a b c d e
2 drbtt 2 d r b t t
Linlin
Thanks. But is there a possibility to add some separator or space between values?
yes.
data have;
input id (c1-c5)($);
cards;
1 a b c d e
2 d r b t t
;
data want;
length newvar $ 50;
set have;
newvar=catx('+',of c:);
run;
proc print;run;
Obs newvar id c1 c2 c3 c4 c5
1 a+b+c+d+e 1 a b c d e
2 d+r+b+t+t 2 d r b t t
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.