BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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?
2 REPLIES 2
data_null__
Jade | Level 19
[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]
DanielSantos
Barite | Level 11
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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 594 views
  • 0 likes
  • 3 in conversation