DATA Step, Macro, Functions and more

Concatenating with specific positioning of a record.

Reply
N/A
Posts: 0

Concatenating with specific positioning of a record.

I have 2 data sets Table1 and Table2. They have the same 3 variables Var1, Var2 and Var 3. There is no special sorting order of the 3 variables.

Table1 contains 11 records. Table2 contains only 1 record. I want to make one new table with all the 12 records.

The record from Table2 should be placed as record number 4 in the new data set, so records 1 - 3 comes from Table1:s records with the same number and records 5 - 12 should come fromTable1:s records 4 - 11.

That must be possible to create?
Respected Advisor
Posts: 3,799

Re: Concatenating with specific positioning of a record.

Posted in reply to deleted_user
[pre]
data table1;
do i = 1 to 11;
output;
end;
run;
data table2;
do j = 1;
output;
end;
run;
data table0;
set table1(obs=3) table2 table1(firstobs=4);
run;
proc print;
run;
[/pre]
Super Contributor
Posts: 474

Re: Concatenating with specific positioning of a record.

Posted in reply to deleted_user
And another way to do the same thing.

data table0;
set table1;
output;
/* _N_ holds the current obs number */
if _N_ eq 3 then
do until (_EOF); /* _EOF checks the end of the table2 dataset */
set table2 end = _EOF;
output;
end;
run;

caution, both solutions will totally insert table2 (every row) at row 3 in table1.

Greetings from Portugal.

Daniel Santos at www.cgd.pt.
Ask a Question
Discussion stats
  • 2 replies
  • 100 views
  • 0 likes
  • 3 in conversation