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

Need a help combination of these group (ID,Pract_name,Hospital_name)
if status is Terminate and Inactive then i just want to keep only teminare records.
if status is Active and Inactive then i don't want to delete these records.

 

IDPract_nameHospital_nameStatus
101XYZABCTerminate
101XYZABCInactive
102ZYXCBAActive
102ZYXCBAInactive
103ASDQWEInactive
103ASDQWETerminate
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

It's normally appreciated if you post at least your sample data already via a working data have step as done below. Even better is if you post also some of your not yet working code showing what you tried.

The 2nd bit - code you tried - helps us understand your level of SAS coding expertise which in return allows us to better provide a solution to you that fits your current skill level.

 

Below one way to go.

data have;
  infile datalines truncover dsd dlm=',';
  input (ID Pract_name Hospital_name) ($) Status $10.;
  datalines;
101,XYZ,ABC,Terminate
101,XYZ,ABC,Inactive
102,ZYX,CBA,Active
102,ZYX,CBA,Inactive
103,ASD,QWE,Inactive
103,ASD,QWE,Terminate
;

data want_1;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where=(status="Terminate"))');
        h1.defineKey('id');
        h1.defineDone();
    end;

  set have;

  if h1.check()=0 and Status ne "Terminate" then
    delete;
run;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

It's normally appreciated if you post at least your sample data already via a working data have step as done below. Even better is if you post also some of your not yet working code showing what you tried.

The 2nd bit - code you tried - helps us understand your level of SAS coding expertise which in return allows us to better provide a solution to you that fits your current skill level.

 

Below one way to go.

data have;
  infile datalines truncover dsd dlm=',';
  input (ID Pract_name Hospital_name) ($) Status $10.;
  datalines;
101,XYZ,ABC,Terminate
101,XYZ,ABC,Inactive
102,ZYX,CBA,Active
102,ZYX,CBA,Inactive
103,ASD,QWE,Inactive
103,ASD,QWE,Terminate
;

data want_1;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where=(status="Terminate"))');
        h1.defineKey('id');
        h1.defineDone();
    end;

  set have;

  if h1.check()=0 and Status ne "Terminate" then
    delete;
run;
Spintu
Quartz | Level 8
Thank you so much for you inputs. I appreciate your comments. that's really going to help me.

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
  • 2 replies
  • 821 views
  • 2 likes
  • 2 in conversation