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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 15 replies
  • 2283 views
  • 3 likes
  • 3 in conversation