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

Hi Folks,

 

I'm trying to create a data of patients who fulfills the following criteria:

 

Keep IF: First observation of the patient
Delete IF: Less than 12 mo since the last eligible data by patients

 

In other words:

wanted for 12 mo spaced data.png

 

The observation needs to be compared to the last eligible data. For instance, for the second subject (PAT_ID=2), third row is eligible because time passed since the last eligible observation is longer than 12 mo. The last eligible observation is the first row. Because second row was deleted due to its ineligibility.

 

DATA HAVE; 
INPUT PAT_ID DATE_VISITS DIFF_VISITS;
CARDS;
1	15391	.
1	15573	5.98
1	15945	12.22
2	15406	.
2	15586	5.92
2	15798	6.96
3	15775	.
3	16139	11.96
3	16321	5.98
4	15439	.
4	15621	5.97
4	16349	23.92
5	15438	.
5	15655	7.13
5	16019	11.96
6	15349	.
6	15558	6.87
6	15768	6.9
;

If you wonder why do this?

The biological marker concerned here is not highly dynamic over time. Therefore, you would not want to make a premature decision based on the observations captured over less than 12 months in between at least.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

DATA HAVE; 
INPUT PAT_ID DATE_VISITS DIFF_VISITS;
format DATE_VISITS date9.;
CARDS;
1	15391	.
1	15573	5.98
1	15945	12.22
2	15406	.
2	15586	5.92
2	15798	6.96
3	15775	.
3	16139	11.96
3	16321	5.98
4	15439	.
4	15621	5.97
4	16349	23.92
5	15438	.
5	15655	7.13
5	16019	11.96
6	15349	.
6	15558	6.87
6	15768	6.9
;

data want;
set have;
by PAT_ID;
retain d;
if first.pat_id then do;output; d=DATE_VISITS;end;
else do;
	dif=intck('month',d,DATE_VISITS);
	if dif>=12 then do;output;d=DATE_VISITS;end;
end;
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

DATA HAVE; 
INPUT PAT_ID DATE_VISITS DIFF_VISITS;
format DATE_VISITS date9.;
CARDS;
1	15391	.
1	15573	5.98
1	15945	12.22
2	15406	.
2	15586	5.92
2	15798	6.96
3	15775	.
3	16139	11.96
3	16321	5.98
4	15439	.
4	15621	5.97
4	16349	23.92
5	15438	.
5	15655	7.13
5	16019	11.96
6	15349	.
6	15558	6.87
6	15768	6.9
;

data want;
set have;
by PAT_ID;
retain d;
if first.pat_id then do;output; d=DATE_VISITS;end;
else do;
	dif=intck('month',d,DATE_VISITS);
	if dif>=12 then do;output;d=DATE_VISITS;end;
end;
run;
novinosrin
Tourmaline | Level 20

@Cruise 

 

Add the  drop statement

 

drop d dif

to the previous

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
  • 4 replies
  • 580 views
  • 2 likes
  • 2 in conversation