BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

It depends.

you can use JOIN to get the column from another dataset or use the code below to insert an empty column:

 

data have;
input id age;
cards;
1 20
2 30
;
proc sql;
create table want
   as select *, ' ' format=$8. as new_col from have;
quit;
proc print;run;

From @Reeza:

 

If you need to add a new column you can use SQL to alter the table as well - i.e. add a column called grade to the class table:

  

data class;
set sashelp.class;
run;
  
proc sql;
   alter table class
      add grade num label='School Grade' format=6.2;
quit;

 

View solution in original post

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

It depends.

you can use JOIN to get the column from another dataset or use the code below to insert an empty column:

 

data have;
input id age;
cards;
1 20
2 30
;
proc sql;
create table want
   as select *, ' ' format=$8. as new_col from have;
quit;
proc print;run;

From @Reeza:

 

If you need to add a new column you can use SQL to alter the table as well - i.e. add a column called grade to the class table:

  

data class;
set sashelp.class;
run;
  
proc sql;
   alter table class
      add grade num label='School Grade' format=6.2;
quit;

 

Reeza
Super User

If you need to add a new column you can use SQL to alter the table as well

IE add a column called grade to the class table:

data class;

set sashelp.class;

run;

proc sql;

   alter table class

      add grade num label='School Grade' format=6.2;

quit;

Haikuo
Onyx | Level 15

if you are asking to add (insert) columns to the existing table, take a look at this page:

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002294523.htm

PROC SQL <option(s)>;
ALTER TABLE table-name
<ADD column-definition<, ... column-definition>>

Haikuo

Mike_Davis
Fluorite | Level 6


Thank you all.

LinLin's method and Reeza and Haikuo's methods all works,

LinLin's method create a new dataset but the other not, except this what is the other main difference?

Thanks

Howles
Quartz | Level 8

Reeza and Haikuo both use the ALTER statement. I believe that this implicitly causes the creation of a new table to replace the old one.

This can be demonstrated by toggling the REPLACE system option to NOREPLACE before invoking ALTER.

Mike.Davis wrote:


Thank you all.

LinLin's method and Reeza and Haikuo's methods all works,

LinLin's method create a new dataset but the other not, except this what is the other main difference?

Thanks

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 130066 views
  • 3 likes
  • 5 in conversation