SAS is a JIT compiled language. It reads of code block, compiles it, and then executes it.
[pre]
Proc Compare ...;
run;
[/pre]
Is a textual block that is compiled to machine code and then executed.
next
[pre]
Proc Sql;
Select ....;
[/pre]
is compiled and executed.
If you wanted to use compare the sorted files, you need to
[pre]
proc sort data=indata1 out=outdata1; by key_value;
proc sort data=indata2 out=outdata2; by key_value;
proc compare data=outdata1 compare=outdata2;
run;
quit;
[/pre]
Or to use proc sql
[pre]
proc sql;
create table outdata1 as
select * from ... where ... order by ... ;
create table outdata2 as
select * from ... where ... order by ... ;
quit;
proc compare ... ;
run;
quit;
[/pre]