BookmarkSubscribeRSS Feed
ravindra2
Fluorite | Level 6

how to compare two datasets with proc sql ?

5 REPLIES 5
Kurt_Bremser
Super User

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.

PeterClemmensen
Tourmaline | Level 20

In most cases, PROC COMPARE is the way to go here. What do you want to compare? Be more specific please

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Clash
Obsidian | Level 7

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,

 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

maybe something like this

 

 proc compare base = _only_Class_1
           compare = _only_Class_2 out=review outall outnoequal;
     by _all_;
 run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 862 views
  • 0 likes
  • 6 in conversation