BookmarkSubscribeRSS Feed
SeanZ
Obsidian | Level 7

Hi, I use proc sql procedure to merge two dataset A and B. I wonder in the default merging process, all the observations in the merged dataset will be only matched observations or they include unmatched ones? Also, how to identify whether the unmatched ones are from A or B. I want to a new variable to show this information (like variable merge with values 1-A, 2-B, or 3-both A & B).

Thank you.

1 REPLY 1
FredrikE
Rhodochrosite | Level 12

The type of join condition descides how the "merge" is done. Using full join selects all rows from each tabe.

This example might work?

data a;
length a a1 $10;
input a a1;
datalines;
two hands
tree hands
;
run;

data b;
length b b1 $10;
input b b1;
datalines;
one leg
two legs
;
run;

proc sql;
create table c as
select coalesce(a.a, b.b) as c
  ,a.a1
  ,b.b1
  ,ifc(missing(a.a),'N','J') as ina
  ,ifc(missing(b.b),'N','J') as inb
from a
   full join b
   on a.a = b.b
;
quit;

//Fredrik

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1620 views
  • 0 likes
  • 2 in conversation