how to compare two datasets with proc sql ?
Maxim 14: Use the Right Tool. Which is proc compare.
For more details, post example data for your datasets (in data steps with datalines), and what you want to particularly compare.
In most cases, PROC COMPARE is the way to go here. What do you want to compare? Be more specific please
In what sense? If you want those in one not the other, then you could do:
proc sql; create table want as select * from table1 except select * from table2; quit;
But generally proc compare would be better.
Hi!
Similiar to Proc Sql with execpt you could use merge -->
Data _Class_1 _Class_2 ;
Set sashelp.class ;
OUTPUT ;
if name = "Alfred" then do ;
name ="Anders" ;
OUTPUT _Class_2 ;
end ;
Run ;
Proc Sort Data=_Class_1 ;
BY _all_ ;
Run ;
Proc Sort Data=_Class_2 ;
BY _all_ ;
Run ;
Data _in_both
_only_Class_1
_only_Class_2 ;
Merge _Class_1(in=in1) _Class_2(in=in2) ;
BY _all_ ;
if in1=1 then do ;
if in2=1 then OUTPUT _in_both ;
else OUTPUT _only_Class_1 ;
end ;
else OUTPUT _only_Class_2 ;
Run ;
Though, Proc Compare would be the best choice...
Regards,
maybe something like this
proc compare base = _only_Class_1
compare = _only_Class_2 out=review outall outnoequal;
by _all_;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.