Here are the data sets a, b, c, and d in a clockwise order. And here are the queries. proc sql;
create table c as
select coalesce(a.a,b.a) as a,b,c
FROM A FULL JOIN B
on a.a=b.a
order by monotonic();
create table d as
select coalesce(a.a,b.a) as a,b,c
FROM B FULL JOIN A
on a.a=b.a
order by monotonic();
quit; There is no problem in the first query. The first observation for this query is the first observation of the data set a—i.e. (1,1.8048229506) because the FULL JOIN uses A first and then B. The problem is the second query. The FULL JOIN in the second query uses B first and then A, so the first observation for this second query should be the first observation of the data set b—i.e. (5,1.8048229506). However, SQL put the last observation of the data set b (1,-1.083317655) as the first observation despite the ORDER BY MONOTONIC() at the end. With the data set b only, the MONOTONIC() assigns 1 for (5,1.8048), 2 for (3,-0.0799), 3 for (2,0.3966), and 4 for (1,-1.0833), and the outer ORDER BY sorts the observations in this order. Why did SAS flip this order when the data set a is incorporated through FULL JOIN? This doesn't happen when not FULL JOIN but just JOIN—in this case, MONOTONIC() assigns 1 for (3,-0.0799), 2 for (2,0.3966), and 3 for (1,-1.0833) orderly, so the resulting data set respects their order as well.
... View more