Search notes:

SAS: adding a column to a dataset

data tq84_source;

  length
     def  8.
     abc  $5
     lmn  8.
     ijk  $5;

  def = 1; abc = 'abc'; lmn = 11; ijk = 'ijk'; output;
  def = 2; abc = 'ABC'; lmn = 22; ijk = 'IJK'; output;

run;



data tq84_new_column_prepended;

/* By mentioning the newly added column before
   the set statement, the column gets prepended
   in the created dataset. */

   length added $5;
   set tq84_source;

   added = 'added';

run;

proc sql;
  describe table tq84_new_column_prepended;
quit;
/*
create table WORK.TQ84_NEW_COLUMN_PREPENDED( bufsize=65536 )
  (
   added char(5),
   def num,
   abc char(5),
   lmn num,
   ijk char(5)
  );
*/ 



data tq84_new_column_appended;

   set tq84_source;
/* By mentioning the newly added column
   after the set statement, the column
   get added after the already existing
   ones. */

   attrib added length=8. format=date.; 

   added = def;

run;

proc sql;
  describe table tq84_new_column_appended;
quit;
/*
create table WORK.TQ84_NEW_COLUMN_APPENDED( bufsize=65536 )
  (
   def num,
   abc char(5),
   lmn num,
   ijk char(5),
   added num format=DATE.
  );
*/
Github repository about-SAS, path: /programming/data-sets/add-column.sas
With proc sql, a column can be added with alter table ... add ....

See also

Change datatypes in a data set
data sets

Index