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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.