Mathias
Mathias

Reputation: 69

Merge two datasets where one has extra column SAS: proc sql

I am trying to merge two data sets with a lot of the same observations except one has a column more. Dataset1 contains data for 20% of the observations and Dataset2 contains observations for the other 80% (+ one column extra). If i run the code below, I get 4037 observations when i merge the two datasets with 315 observation!

proc sql;
create table RateExposure as
select *
from Dataset1, Dataset2
where Dataset1.ID = Dataset2.ID
order by Dataset1.ID;
quit;

If I run

data newDataset;
merge Dataset1 Dataset2;
by ID;
run;

I only get observation for one of the datasets - how can this be?

Upvotes: 0

Views: 320

Answers (1)

andrey_sz
andrey_sz

Reputation: 751

Try this:

PROC SQL;
CREATE TABLE result AS
SELECT t1.*, t2.extra_column
FROM Dataset1 AS t1
INNER JOIN Dataset2 AS t2 ON (t1.ID = t2.ID)
;
QUIT;

Upvotes: 0

Related Questions