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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 3 replies
  • 521 views
  • 0 likes
  • 3 in conversation