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.
ID | Pract_name | Hospital_name | Status |
101 | XYZ | ABC | Terminate |
101 | XYZ | ABC | Inactive |
102 | ZYX | CBA | Active |
102 | ZYX | CBA | Inactive |
103 | ASD | QWE | Inactive |
103 | ASD | QWE | Terminate |
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;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.