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
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;
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;
Hey thanks so much. This worked really well with my code.
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.
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.
Ready to level-up your skills? Choose your own adventure.