SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
franriv
Obsidian | Level 7

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

You can as long as you use logic which doesn't re-create the table. 

data example(index=(my_index=(id visit)));
  input id visit$ visit_num var1 var2 var3;
  datalines;
1 Visit1 1 20 30 35
1 Visit2 2 75 35 45
2 Visit1 3 99 15 34
2 Visit2 4 55 38 48
;
run;

/* add column to existing table */
proc sql;
  alter table example
    add test NUM
    ;
quit;

/* populate column with value - option 1*/
proc sql;
  update example
    set test=1
    ;
quit;

/* populate column with value - option 2*/
data example;
  modify example;
  test=2;
run;

proc contents data=example;
run;
 

 

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

Interesting question. In your scenario, i'd probably go for proc datasets index create or using proc sql. Well, not claiming anything but just a thought

Patrick
Opal | Level 21

You can as long as you use logic which doesn't re-create the table. 

data example(index=(my_index=(id visit)));
  input id visit$ visit_num var1 var2 var3;
  datalines;
1 Visit1 1 20 30 35
1 Visit2 2 75 35 45
2 Visit1 3 99 15 34
2 Visit2 4 55 38 48
;
run;

/* add column to existing table */
proc sql;
  alter table example
    add test NUM
    ;
quit;

/* populate column with value - option 1*/
proc sql;
  update example
    set test=1
    ;
quit;

/* populate column with value - option 2*/
data example;
  modify example;
  test=2;
run;

proc contents data=example;
run;
 

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Thanks for the example's and reminder @Patrick,  

franriv
Obsidian | Level 7
is it possible to do it without using proc sql?
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

any thing is possible.  Why make it hard to do?  if you want to create a new world then lets do it in DOS.

 

Tom
Super User Tom
Super User

Why?  If you are adding a column to the dataset then you are making a new dataset.

So just make the new dataset.  Create the index as you make the new dataset.

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!

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