BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
art297
Opal | Level 21

: Hopefully, someone more versed in SQL, than me, can show you how this code SHOULD be written.  However, the following two sets of code do the two tasks that you asked about.  The good news is that, while probably doing it in a more round about way than necessary, both will work regardless of whether there are any many-to-many situations:

/*create two test files*/

data file_a;

  input geid goc x y z;

  cards;

1 1 1 2 3

2 1 1 2 3

3 1 1 2 3

4 1 1 2 3

5 1 1 2 3

;

data file_b;

  input geid goc a b c;

  cards;

1 1 4 5 6

2 2 4 5 6

7 1 4 5 6

8 1 4 5 6

9 1 4 5 6

;

proc sql;

  create table work.met_condition as

    select * from

   (select geid from work.file_a

         except

         select geid from work.file_b)

   union

   (select geid from work.file_b

         except

         select geid from work.file_a)

  ;

  create table work.all_combined as

    select * from work.file_a

      union

        select * from work.file_b

  ;

  create table work.file_discrepancies (drop=b_:) as

    select *

      from work.met_condition a,

           work.all_combined (rename=(geid=b_geid)) b

        where a.geid=b.b_geid

  ;

quit;

proc sql;

  create table work.met_condition as

    select * from

   (select geid,goc from work.file_a

         except

         select geid,goc from work.file_b)

   union

   (select geid,goc from work.file_b

         except

         select geid,goc from work.file_a)

  ;

  create table work.all_combined as

    select * from work.file_a

      union

        select * from work.file_b

  ;

  create table work.file_discrepancies2 (drop=b_:) as

    select *

      from work.met_condition a,

           work.all_combined (rename=(geid=b_geid

                                      goc=b_goc)) b

        where a.geid=b.b_geid and

              a.goc=b.b_goc

  ;

quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 4225 views
  • 3 likes
  • 3 in conversation