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;
proc contents;
data example;
set example;
test=1;
run;
proc contents;
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;
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
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;
Neat!!!
Thanks for the example's and reminder @Patrick,
any thing is possible. Why make it hard to do? if you want to create a new world then lets do it in DOS.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.