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

I have a data set with two IDs and variable NLEV to identify ID1 duplicates:

 

data have;
 input id1$ id2$ nlev;
cards;
1 A 1
1 A 2
2 B 1
2 B 2
3 C 1
3 C 2
3 C 3
3 B 4
;
run;

How can I verify that values for ID2 only correspond to one unique ID1 value. In this example, I'd want SAS to flag records where ID2="B" (or something similar) because ID2="B" corresponds to both ID1=2 and ID1=3.

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @bkq32   By any chance, is this what you are after?

 

data have;
 input id1$ id2$ nlev;
cards;
1 A 1
1 A 2
2 B 1
2 B 2
3 C 1
3 C 2
3 C 3
3 B 4
;
run;

proc sql;
create table want as
select *, count(distinct id1)>1 as flag
from have
group by id2
order by id1,nlev;
quit;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi @bkq32   By any chance, is this what you are after?

 

data have;
 input id1$ id2$ nlev;
cards;
1 A 1
1 A 2
2 B 1
2 B 2
3 C 1
3 C 2
3 C 3
3 B 4
;
run;

proc sql;
create table want as
select *, count(distinct id1)>1 as flag
from have
group by id2
order by id1,nlev;
quit;
bkq32
Quartz | Level 8

Yes, that's perfect. Thank you!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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