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

I want to delete complete group records based on by group ID Pract_name Hospital_name. if the date value is less than 01/01/2018.

 

IDPract_NameHospital_NameDate
1XYZABC24-Jun-18
1XYZASD 
2XYATVX 
2XYATVX25-Jun-17
2XYATRF 
3WEDDEC25-Jun-19

 

Required Output:

 

IDPract_NameHospital_NameDate
1XYZABC24-Jun-18
1XYZASD 
2XYATRF 
3WEDDEC25-Jun-19
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input ID	Pract_Name $	Hospital_Name $	Date :date9.;
format date date9.;
cards;
1	XYZ	ABC	24-Jun-18
1	XYZ	ASD	 .
2	XYA	TVX	 .
2	XYA	TVX	25-Jun-17
2	XYA	TRF	 .
3	WED	DEC	25-Jun-19
;

proc sql;
  create table want as
  select *
  from have
  group by id, Pract_name, Hospital_name
  having not max (.< date < '01jan2018'd);
quit;

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

What do you mean by "complete group"?

 

Show us the desired output.

--
Paige Miller
Spintu
Quartz | Level 8
I have mentioned as required output
PaigeMiller
Diamond | Level 26

I don't understand "complete group". Please explain.

 

Also explain in more detail the logic that allows you to go from input data set to obtain output data set. Don't make me guess.

--
Paige Miller
novinosrin
Tourmaline | Level 20
data have;
input ID	Pract_Name $	Hospital_Name $	Date :date9.;
format date date9.;
cards;
1	XYZ	ABC	24-Jun-18
1	XYZ	ASD	 .
2	XYA	TVX	 .
2	XYA	TVX	25-Jun-17
2	XYA	TRF	 .
3	WED	DEC	25-Jun-19
;

proc sql;
  create table want as
  select *
  from have
  group by id, Pract_name, Hospital_name
  having not max (.< date < '01jan2018'd);
quit;
novinosrin
Tourmaline | Level 20


data have;
input ID	Pract_Name $	Hospital_Name $	Date :date9.;
format date date9.;
cards;
1	XYZ	ABC	24-Jun-18
1	XYZ	ASD	 .
2	XYA	TVX	 .
2	XYA	TVX	25-Jun-17
2	XYA	TRF	 .
3	WED	DEC	25-Jun-19
;

proc sort data=have out=_have;
  by id Pract_name Hospital_name;
run;
/*Datastep*/
data want;
  do until(last.Hospital_name);
    set _have;
	by id Pract_name Hospital_name notsorted;
	if .< date < '01jan2018'd then _n_=0;
  end;
  do until(last.Hospital_name);
    set _have;
	by id Pract_name Hospital_name notsorted;
	if _n_ then output;
  end;
run;

/*OR*/

data want;
  merge _have _have(where=(.< _date < '01jan2018'd) keep= id Pract_name Hospital_name date rename=date=_date in=a);
  by id Pract_name Hospital_name;
  if not a;
  drop _date;
run;
/*OR*/
data want;
  if _n_=1 then do;
    dcl hash h(dataset:"have(where=(.< date < '01jan2018'd))");
	h.definekey('id', 'Pract_name', 'Hospital_name');
	h.definedone();
  end;
  set have;
  if h.check() ne 0;
run;

novinosrin
Tourmaline | Level 20

data have;
input ID	Pract_Name $	Hospital_Name $	Date :date9.;
format date date9.;
cards;
1	XYZ	ABC	24-Jun-18
1	XYZ	ASD	 .
2	XYA	TVX	 .
2	XYA	TVX	25-Jun-17
2	XYA	TRF	 .
3	WED	DEC	25-Jun-19
;

proc sql;
  create table want as
  select *
  from have
  where cats(id,Pract_name,Hospital_name) not in 
  (select cats(id,Pract_name,Hospital_name) from have where .< date < '01jan2018'd);
quit;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7 replies
  • 1047 views
  • 5 likes
  • 3 in conversation