BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Saurabh_Rana
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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).

Saurabh_Rana
Obsidian | Level 7
But with the data step, I will only get the concatenated column in output table but I want the concatenated column along with the other 100 columns. What is the best way to achieve this output?
Kurt_Bremser
Super User

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1526 views
  • 0 likes
  • 2 in conversation