Good afternoon everyone! I have a dataset where there are multiple records for each member id along with claim numbers and other fields. I want to extract just a sample for two members with all their corresponding multiple records.
Data have;
input mem_id $ claim_id $ amount dos :mmddyy10.;
format dos mmddyy10.;
datalines;
A 1 100 01/01/2017
A 1 200 01/01/2017
A 2 150 01/02/2017
B 3 50 01/01/2018
B 4 70 01/02/2018
C 5 10 01/01/2019
C 5 15 01/01/2019
;
Data want;
input mem_id $ claim_id $ amount dos :mmddyy10.;
format dos mmddyy10.;
datalines;
A 1 100 01/01/2017
A 1 200 01/01/2017
A 2 150 01/02/2017
B 3 50 01/01/2018
B 4 70 01/02/2018
;
Thanks!
How about
proc sort
data=have (keep=mem_id)
out=members (obs=2)
nodupkey
;
by mem_id;
run;
proc sort data=have;
by mem_id dos;
run;
data want;
merge
have
members (in=m)
;
by mem_id;
if m;
run;
(untested, composed on my tablet)
PS I fixed your have and want datastep codes.
How about
proc sort
data=have (keep=mem_id)
out=members (obs=2)
nodupkey
;
by mem_id;
run;
proc sort data=have;
by mem_id dos;
run;
data want;
merge
have
members (in=m)
;
by mem_id;
if m;
run;
(untested, composed on my tablet)
PS I fixed your have and want datastep codes.
Hi,
data want;
set have;
where mem_id in ('A', 'B');
run;
Regards,
Anushree
Thanks , but for this I need to open each dataset every time and find two unique members. Infact i used the same method, but knew it was not very efficient.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: