Hello,
In the data the date difference is the differene between the row's date to the previous date. I want to flag patients where there is difference of >= 120 days and mark all the dates after that >120 days. If there is a patients who have 2 rows of >120 days then I want to mark first >= 120 days to the 2nd >120 days as "R1" and "R2" for dates greater than 2nd >120 days.
Thanks!
I think this is what you are asking for:
data want;
set have;
by patient_ID;
if first.patient_ID then count=0;
drop count;
if difference_between_dates >= 120 then count + 1;
if count > 0 then recurrence = 'R' || put(count, z2.);
run;
I did add a zero in there, using the Z2. format. If you are sure that you will never require double digits to count the number of recurrences, you could change that to the 1. format instead.
Since I won't type off a picture, here's an example with simplified data:
data have;
input patient $ date;
cards;
X 1
X 6
X 130
X 135
X 140
X 350
X 355
;
run;
data want;
set have;
by patient;
retain recurr;
diff = date - lag(date);
if first.patient
then do;
recurr = " ";
diff = 0;
end;
if diff > 120
then do;
if recurr = 'R1'
then recurr = 'R2';
else recurr = 'R1';
end;
run;
I think this is what you are asking for:
data want;
set have;
by patient_ID;
if first.patient_ID then count=0;
drop count;
if difference_between_dates >= 120 then count + 1;
if count > 0 then recurrence = 'R' || put(count, z2.);
run;
I did add a zero in there, using the Z2. format. If you are sure that you will never require double digits to count the number of recurrences, you could change that to the 1. format instead.
Thank you, it worked!
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!
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.