BookmarkSubscribeRSS Feed
longwen
Calcite | Level 5

My data looks like:

ID  Start_day    End_day    

1 - 5/1/20 - 5/31/20
1 - 6/6/20 - 7/5/20
1 - 7/8/20 - 8/7/20
1 - 9/9/20-10/8/20

...

 

I am trying to first calculate the gap between a person's last end day and the next start day. e.g. for person 1, the gap should be 6/6/20 - 5/31/30 =6 days (which I already calculated for each person successfully).

Then, I want to calculate the duration for a person if he/she has no gap > 30 days. e.g. person 1 has gap > 30 days at the 4th row, so the duration should be 8/7/20 minus 5/1/20 (99 days).

Plus,  a person could have multiple durations if he/she has more than one gap (>30 days). e.g. A person could have first duration on 5/1/10 - 5/1/11. Then, he/she have a gap of, for example, 180 days and he/she start another period 11/1/2011 - 1/31/11 and then they could have another gap of > 30 days. Then they could start a third period.

The duration calculation is what I am struggling with.
Any suggestion?
Thanks
3 REPLIES 3
biopharma
Quartz | Level 8
Can you add a few IDs or more rows for the same ID with examples of multiple durations. Present other situations that could be more complex etc..
ballardw
Super User

Question: are your start_day and end_day actually SAS date values?

 

You will in the long run save yourself a lot of headaches later if you get into the habit of using 4 digit years for display (unless of course you have a dinosaur-like boss that requires 2 digit years).

Quick, tell me what the date is in words for 01/02/03.

Without more information you might even get the wrong century.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1067 views
  • 0 likes
  • 4 in conversation