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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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