How can I concatenate multiple columns in PROC SQL statement using ALTER? And I don't want to use SELECT statement since in that case, I will have to mention all the columns and the table on which I am working has more than 100 columns whereas in the ALTER statement you just need to mention the column you are adding.
You will get ALL variables, unless you drop them:
data have;
input x $ y $;
datalines;
a b
;
data want;
set have;
z = cats(x,y);
run;
proc print data=want noobs;
run;
Result:
x y z a b ab
The ALTER TABLE statement can be used to just add a column, but it will initialize it with missing values. You need to also use an UPDATE that sets the values as needed.
I would rather use a DATA step to do this (add a column and use concatenation of values to populate it).
You will get ALL variables, unless you drop them:
data have;
input x $ y $;
datalines;
a b
;
data want;
set have;
z = cats(x,y);
run;
proc print data=want noobs;
run;
Result:
x y z a b ab
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.