1 min read

A Quick Look at SAS DS2 Merge

The code:

data a;
    input i a $ b $;
    datalines;
    1 a1A b1
    1 a1A b1
    2 a2 b2
    ;
run;

data b;
    input i a $ c $;
    datalines;
    1 a1C c1
    2 .   c2
    3 .  c3
    ;
run;

data mrge;
    merge a b;
    by i;
run;

proc ds2;
    data ds2;
       method run();
          merge a b;
        by i;
       end;
     enddata;
    run;
quit;

The outputs:

SAS_DS2_merge

The comments:

1. One of the weird behaviors of data step MERGE is that the value “c1” was carried over to row 2 of merged out dataset, Work.Mrge. In output dataset Work.Ds2 (generated by DS2), the row 2 of variable c is missing, which is kind of safe operation as we expected.

2. In both output datasets, value ‘a1C’ overwrote ‘a1A’ in row 1.

3. This DS2 MERGE is available in SAS 9.4 (TS1M3).