Andrew Engel
Andrew Engel

Reputation: 1

Merging 2 SAS data sets, resulting in 0 observations

I am trying to merge two datasets, set one contains ID and location, set two contains customer information, including the same ID as set one. I have tried a couple different methods to try to do this, the most recent I have been trying is:

Data Work.merged;
   merge Work.dataone (in = in1)
   Work.datatwo (in = in2);
by id location;
if in1 and in2;
Run;

This is outputting a dataset 'merged' that contains 0 observations, SAS output no error or warning messages in log.

Thank you for any help!

Upvotes: 0

Views: 715

Answers (1)

Quentin
Quentin

Reputation: 6378

Your IF statement is selecting only the records where there is a match from both datasets. If work.merged has 0 records, that means there are no matches. The easiest way to see the records that don’t match is to add a PUT statement to write those records to the log.

Consider:

data work.merged ;
  merge 
    work.dataone (in = in1)
    work.datatwo (in = in2)
  ;
  by id location;
  if not (in1 and in2) then put “Mismatch” (id location in1 in2)(=) ;
  if in1 and in2 ;
run ;

Upvotes: 2

Related Questions