BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
loishaggard
Fluorite | Level 6

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!

 

001230402AUG2020
001230426JUL2020
001230426JUL2020
001230423JUL2020
003305603AUG2020
003305622JUL2020
005126303AUG2020
005126328JUL2020
005126321JUL2020
007558410AUG2020
007558408AUG2020
018627831JUL2020
018627817JUL2020
019500010AUG2020
019500030JUL2020
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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;
loishaggard
Fluorite | Level 6
Perfect. You rock!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 414 views
  • 0 likes
  • 2 in conversation