/* Merging data */ *First we read in a test data set for you; data mydata; input OBS Y VAR1 VAR2 VAR3; cards; 1 1 10 33 4 2 0 20 21 3 3 1 30 59 2 17 1 20 76 1 5 2 . 24 3 6 0 20 22 2 7 1 10 28 2 8 1 10 49 2 9 0 30 76 2 10 2 20 59 2 ; *Creating an additional dataset (5 observations) for merging illustration ; data test(keep=var4-var6 OBS); set mydata; OBS=_n_; VAR4=Var1*10; VAR5=VAR2*10; VAR6=VAR3*10; if OBS>5 then delete; run; *must always remember to sort tables based on what you plan to join them with; proc sort data=mydata;by OBS;run; proc sort data=test;by OBS;run; *Example 1 - Include all observations from first table (Mymodel); Data merged; merge mydata (in=a) test ; by OBS; if a; run; Title Merged Table (Include all from First table); proc print data=merged;run; *Example 2 - Include only observations from second table (test); Data merged; merge mydata (in=a) test(in=b); by OBS; if b; run; Title Merged Table (Include all from 2nd table); proc print data=merged;run; *Example 2 - Include only observations common to both); Data merged; merge mydata (in=a) test(in=b); by OBS; if a and b; run; Title Merged Table (Include observations common to both); proc print data=merged;run;