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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

anushreebiotech
Obsidian | Level 7

Hi,

 

data want;
set have;
where mem_id in ('A', 'B');
run;

 

Regards,

Anushree

devsas
Pyrite | Level 9

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1098 views
  • 0 likes
  • 3 in conversation