SAS Duplicate Indicator

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

SAS Duplicate Indicator

 So I have an issue that I am not sure how to solve.  

 

I have two datasets:

Dataset 1: mbr_num, client_id_count

Dataset 2: mbr_num, client_id

 

So my first dataset shows the member number and the number of clients the member number is associated with.  Dataset 2 is showing just the member number and the client id.

 

I want to be able to build an if statement that will do the following:

1) Flag the mbr_num on the 2nd dataset that has a duplicate (associated to more than 1 client id)

2) Only flag the first instence of the member who has a duplicate (if.first type statement)

 

So that is basically it.  I am just not sure the syntax to use to best bring that together.  

 

I am using Base SAS 9.2


Accepted Solutions
Solution
‎10-13-2016 02:56 PM
Super User
Posts: 11,139

Re: SAS Duplicate Indicator

It helps to provide data. See if this helps:

 

data work.set1;
   input   mbr_num client_id_count;
datalines;
1     1
2     2
3     1
4     4
;
run;

data work.set2;
   input mbr_num client_id $;
datalines;
1  abc
2  pdq
2  xyz
3  jjj
4  eft
4  ghe
4  jkl
4  mno
;
run;

data work.want;
   merge
      work.set2 (In=In2 )
      work.set1 (In=In1 where=(client_id_count>1))
  ;
  by mbr_num;
  if first.mbr_num and In2 and In1 then Flag=1;
  drop  client_id_count;
run;
      

View solution in original post


All Replies
Solution
‎10-13-2016 02:56 PM
Super User
Posts: 11,139

Re: SAS Duplicate Indicator

It helps to provide data. See if this helps:

 

data work.set1;
   input   mbr_num client_id_count;
datalines;
1     1
2     2
3     1
4     4
;
run;

data work.set2;
   input mbr_num client_id $;
datalines;
1  abc
2  pdq
2  xyz
3  jjj
4  eft
4  ghe
4  jkl
4  mno
;
run;

data work.want;
   merge
      work.set2 (In=In2 )
      work.set1 (In=In1 where=(client_id_count>1))
  ;
  by mbr_num;
  if first.mbr_num and In2 and In1 then Flag=1;
  drop  client_id_count;
run;
      
Contributor
Posts: 23

Re: SAS Duplicate Indicator

Hey thanks so much.  This worked really well with my code.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 507 views
  • 1 like
  • 2 in conversation