BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
frakje
Calcite | Level 5

Hello

 

I have two datasets. Lets call them dataset1 and dataset2.

 

I want to create a third dataset who contains records not in both dataset based on my keyvar.

 

Thank you!

 

Kind regards Frank

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

See this simplified example:

data one;
input CPR $;
datalines;
123
456
789
;

data two;
input CPR $;
datalines;
000
123
789
;

data check;
merge
  one (in=one)
  two (in=two)
;
by CPR;
if not (one and two);
run;

Both datasets need to be sorted by CPR.

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

How can you create a third dataset who contains records not in "both" dataset based on my keyvar.

 

Are you looking for EXCEPT rule?

frakje
Calcite | Level 5

Let me try to explain.

 

I have two different datasets with different variables. Both of them contain a Danish 'CPR' number which in this situation is my ID var.

 

A patient can be in dataset1 and not in dataset2 and opposite. I want to find those patients whos not in both datasets based on my ID var.

 

In STATA I can use 'merge' and choose those patients where there is no match.

 

Can I do something similar in sas?

 

 

 

 

 

Kurt_Bremser
Super User

See this simplified example:

data one;
input CPR $;
datalines;
123
456
789
;

data two;
input CPR $;
datalines;
000
123
789
;

data check;
merge
  one (in=one)
  two (in=two)
;
by CPR;
if not (one and two);
run;

Both datasets need to be sorted by CPR.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 683 views
  • 0 likes
  • 3 in conversation