Open 1to1 left.csv | Open 1to1 right.csv |
*To import the data;
proc import datafile = 'C:/1to1 left.csv' out = l_data dbms = csv replace;
getnames = yes;
run;
proc import datafile = 'C:/1to1 right.csv' out = r_data dbms = csv replace;
getnames = yes;
run;
Option 1: Merge using a data step
* Datasets MUST be sorted on Key variable prior to merging; proc sort data = l_data; by Key; run; proc sort data = r_data; by Key; run; * The in = left option creates a temporary variable, left, that indicates if the observation was originally in the left dataset; * The if left and right statement, keeps only observations where right = 1 and left = 1; data inner; merge l_data(in = left) r_data(in = right); by Key; if left and right; run; |
Option 2: Merge using proc sql
* Datasets do not need to be previously sorted; * Refer to l_data as dataset a and r_data as dataset b; * Select all variables from l_data and the Fruits variable from r_data; proc sql; create table sql_inner as select a.*, b.fruits from l_data a, r_data b where a.Key = b.Key ; quit; *Alternatively instead of a where statement, specify an inner join in the from statement on a.Key = b.Key; proc sql; create table sql_inner as select a.*, b.fruits from l_data a inner join r_data b on a.Key = b.Key ; quit; |
Functions referenced:
More information:
data step: merge vs proc sql: join
--- The End ---