Print ID numbers from two datasets

Accepted Solution Solved
Reply
Regular Contributor
Posts: 150
Accepted Solution

Print ID numbers from two datasets

I am merging two data sets together, one with 291 observations and one with 289 but the result gives me 302 observations with no duplicates. Is there a way to print the ID numbers next to each other from the two data sets so I can see which are different? Any help would be appreciated.


Accepted Solutions
Solution
‎08-28-2014 03:05 PM
Super User
Posts: 11,114

Re: Print ID numbers from two datasets

How about looking directly for the mismatches?

This code shows which ID are in the first set but not the second, then those in the second set but not the first.

proc sql;

  title 'A EXCEPT B';

  select id from firstDatasetnamehere

  except

  select id from secondDatasetnamehere

  ;

  title 'B EXCEPT A';

  select id from secondDatasetnamehere

  except

  select id from firstDatasetnamehere

;

quit;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,228

Re: Print ID numbers from two datasets

If you can share more information like data, merging key and method used for merging then it would be easier to suggest some solution.

Regular Contributor
Posts: 150

Re: Print ID numbers from two datasets

I am using a data step to merge the data:

data newdata;

merge olddata1 olddata2;

by pid;

run;

I am not sure what other information I could share. One dataset is lab data and the other is survey data. I am just trying to not have to physically print the list of list numbers and compare them from two sheets of paper, it would be easier if the ID numbers were next to each other. I guess one option would be to greate a new variable in the lab dataset that indicates a variable is only in the lab data and print that alongside the ID numbers. That way if the variable is missing for the survey data that ID number does not exist in the survey data. That is the best I can come up with but there has to be a better way. Thanks again.

Solution
‎08-28-2014 03:05 PM
Super User
Posts: 11,114

Re: Print ID numbers from two datasets

How about looking directly for the mismatches?

This code shows which ID are in the first set but not the second, then those in the second set but not the first.

proc sql;

  title 'A EXCEPT B';

  select id from firstDatasetnamehere

  except

  select id from secondDatasetnamehere

  ;

  title 'B EXCEPT A';

  select id from secondDatasetnamehere

  except

  select id from firstDatasetnamehere

;

quit;

Regular Contributor
Posts: 150

Re: Print ID numbers from two datasets

This is prefect and exactly what I was hoping for, thank you!!!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 219 views
  • 0 likes
  • 3 in conversation