In the example that was provided, when I run the code below and compare the PROC SQL results to the Merge, before the final step of concatenating with the original data set (t1), the data sets are the same for each ID value; although the order of the observations is different.
Data t1;
input id x y year;
cards;
1 19 29 2025
2 10 15 2025
3 30 29 2025
;
run;
Data t2;
input id x y year;
cards;
1 34 36 2024
3 23 12 2024
;
run;
Data t3;
input id x y year;
cards;
2 56 23 2023
5 18 17 2023
7 43 23 2023
;
run;
proc sql;
create table t2_pop as
select a.*
from t2 as a
inner join t1 as b
on a.id=b.id
;
quit;
/*proc print data=t2_pop;*/
/*run;*/
proc sql;
create table t3_pop as
select a.*
from t3 as a
inner join t1 as b
on a.id=b.id
;
quit;
/*proc print data=t3_pop;*/
/*run;*/
data combine;
set t2_pop t3_pop;
run;
title 'Data set from 2 SQL steps';
proc print data=combine;
run;
data combine1;
merge t1(in=a) t2(in=b) t3(in=c);
by id;
if a;
run;
title 'Data set from Merge';
proc print data=combine1;
run;
Data set from 2 SQL steps 15:12 Tuesday, July 1, 2025 4
Obs id x y year
1 1 34 36 2024
2 3 23 12 2024
3 2 56 23 2023
Data set from Merge 15:12 Tuesday, July 1, 2025 5
Obs id x y year
1 1 34 36 2024
2 2 56 23 2023
3 3 23 12 2024
... View more