🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 01-11-2019 08:01 PM
(1107 views)
is it possible to create a new variable without indexes being deleted?
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;
i want the index to stay in place after creating new variable (not sure if it's possible)
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
7 REPLIES 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Neat!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the example's and reminder @Patrick,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
is it possible to do it without using proc sql?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
any thing is possible. Why make it hard to do? if you want to create a new world then lets do it in DOS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.