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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1556 views
  • 0 likes
  • 2 in conversation