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

 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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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;
      
IgawaKei29
Quartz | Level 8

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1346 views
  • 1 like
  • 2 in conversation