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.

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