DATA Step, Macro, Functions and more

How to Compare fields in Two Different Datasets

Occasional Contributor
Posts: 11

How to Compare fields in Two Different Datasets

Hello All,


I have two different datasets that provide info on claim amount paid by two different sources.  Each  set includes the claimant name, the date of incident, and the amount paid.  So let's say Name1, Date1, and Paid 1 are fields in Set #1, and Name2, Date2, and Paid2 are fields in Set #2.  Each of the two sets includes other fields that are not totally identical.  What I need to do is to find out those claimants who are in both sets of data, i.e., Name1=Name2, and were injured on the same date and so Date1=Date2, and then create a new field named as TotalPaid = Paid1+Paid2.  That is, I need to find out the total amount of paid for each claimant from both sources.  For those claimants exist only in one and not both sets, then TotalPaid=0.  The rationale of using these two conditions to set up the new field is because it is not likely that two individuals who got injured on the same date will have the same name.  How can I do that?  Thanks for helping.  

Super User
Posts: 23,663

Re: How to Compare fields in Two Different Datasets

Post sample data and expected output - not real data because you obviously can't release that, but some data that's similar to what you have, especially if you want code. 


Things that are unclear in your current question:

  • Do you want the final dataset to have all people, only people in first dataset, only people in second, only people in both?
  • Are the formats/type the same between the two for merges - they have to be.
  • When I've worked with medical data and we also used a window, not a specific date=date, because a lot of times a wait in an ER can stretch over midnight which means dates for things may be off by at minimum one date. If this isn't a concern feel free to ignore this comment Smiley Happy

Otherwise this is most likely more easy to accomplish in SQL though a data step merge is also possible. 


Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation