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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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