Reputation: 21
I know that I can use PROC SQL INSERT INTO (_Table_Name_) values('Value') or by using INSERT INTO SET Variable Name=numeric_value or 'char_value'
but my question is: how do I make sure that this value appears on top of the dataset instead of the default bottom position?
data temp;
input x y;
datalines;
1 2
3 4
5 6
;
run;
proc sql;
insert into work.temp
(x,y)
values (8,9);
quit;
Upvotes: 1
Views: 3361
Reputation: 63424
You cannot insert values "on top" of the dataset without rewriting the dataset. INSERT (and PROC APPEND) work by avoiding rewriting the entire dataset, instead just adding the rows to the bottom. SAS has a defined data structure where observations are physically stored in the order they will be processed in when normal, sequential processing is used (as opposed to index-based or random-access methods).
To put rows at the "top" of the dataset, simply create a new dataset (which can use the same name, if you choose, though it will be a different dataset technically) and add them however you choose; even something as simple as below would work, though I'd put the data-to-be-inserted into a separate dataset in a real application (as it probably would come from a different data source).
data temp;
if _n_=1 then do; *if on first iteration, add things here;
x=8;
y=9;
output; *outputs the new record;
end;
set temp;
output; *outputs the original record;
run;
Upvotes: 3
Reputation: 15657
you can do this in a data step as follows:
data a;
x=1;
y=2;
output;
x=3;
y=4;
output;
run;
data b;
x=7;
y=8;
output;
run;
data c;
set b a;
run;
Upvotes: 0