I need to filter out any lab reports that had a previous report for the same patient ID within the past 30 days. Here are the patient ID and date fields for a set of records, grouped by patient ID. As you can see, patient ID 0012304 had four lab reports. It looks like the one on July 23rd was the original report. Records for the other, later reports should be deleted because they are within the 30-day window.
Thanks for the help!
| 0012304 | 02AUG2020 | 
| 0012304 | 26JUL2020 | 
| 0012304 | 26JUL2020 | 
| 0012304 | 23JUL2020 | 
| 0033056 | 03AUG2020 | 
| 0033056 | 22JUL2020 | 
| 0051263 | 03AUG2020 | 
| 0051263 | 28JUL2020 | 
| 0051263 | 21JUL2020 | 
| 0075584 | 10AUG2020 | 
| 0075584 | 08AUG2020 | 
| 0186278 | 31JUL2020 | 
| 0186278 | 17JUL2020 | 
| 0195000 | 10AUG2020 | 
| 0195000 | 30JUL2020 | 
HI @loishaggard
data have;
input id date date9.;
format date date9.;
cards;
0012304	02AUG2020
0012304	26JUL2020
0012304	26JUL2020
0012304	23JUL2020
0033056	03AUG2020
0033056	22JUL2020
0051263	03AUG2020
0051263	28JUL2020
0051263	21JUL2020
0075584	10AUG2020
0075584	08AUG2020
0186278	31JUL2020
0186278	17JUL2020
0195000	10AUG2020
0195000	30JUL2020
;
proc sort data=have;
by id date;
run;
data want;
 do until(last.id);
  set have;
  by id;
  if first.id or intck('day',_n_,date)>30 then do;
   output;
   _n_=date;	
  end;
 end;
run;
					
				
			
			
				
			
			
			
				
			
			
			
			
			
		HI @loishaggard
data have;
input id date date9.;
format date date9.;
cards;
0012304	02AUG2020
0012304	26JUL2020
0012304	26JUL2020
0012304	23JUL2020
0033056	03AUG2020
0033056	22JUL2020
0051263	03AUG2020
0051263	28JUL2020
0051263	21JUL2020
0075584	10AUG2020
0075584	08AUG2020
0186278	31JUL2020
0186278	17JUL2020
0195000	10AUG2020
0195000	30JUL2020
;
proc sort data=have;
by id date;
run;
data want;
 do until(last.id);
  set have;
  by id;
  if first.id or intck('day',_n_,date)>30 then do;
   output;
   _n_=date;	
  end;
 end;
run;
					
				
			
			
				
			
			
			
			
			
			
			
		It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.