I don't understand how SAS merge treats columns if you have the same column name in 3 tables with different values

50 Views Asked by At

I have a REC column that can be found in three tables: GRAV, ATTRI and SIN_TOT. I want to know in the final result of this code, SAS it takes the REC column of which table exactly? knowing that there are different values between the REC column of each table.

data plafond_dos;
    
        merge grave (in=a)
              attri (in=b)
              sin_tot (in=c)
        ;
        if a;
        by exer_sin anc_ref cont; 
run;
1

There are 1 best solutions below

0
PBulls On

See here for documentation on this topic, summarizing briefly:

  • for the first observation in a by group any shared non-by variable will take the value of the last dataset (as they appear in the merge statement) it was read from.
  • all next records within the by group will implicitly retain the value from the first dataset the variable was read from.

Obviously, it depends on which by combinations exist in each of your datasets to determine which of those will be first and last in each group.