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

Hello,

Untitled.png

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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;
Astounding
PROC Star

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.

Sujithpeta
Quartz | Level 8

Thank you, it worked!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1968 views
  • 1 like
  • 3 in conversation