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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 7 replies
  • 1142 views
  • 5 likes
  • 3 in conversation