Greetings!
I'm looking for some assistance in calculating the amount of time between multiple dates by subject id and time point in a long formatted data set. An example of the data format is below:
ID | Completed Date | Timepoint | Time |
1 | 2/19/2018 | 1 | 0 |
1 | 2/20/2018 | 2 | |
1 | 2/21/2018 | 3 | |
2 | 2/13/2018 | 1 | 0 |
2 | 2/14/2018 | 2 | |
2 | 2/15/2018 | 3 | |
3 | 2/15/2015 | 1 | 0 |
3 | 2/16/2015 | 2 |
Thanks in advance for your assistance!
v/r,
Torrance
It's not clear what you want as output, however, look at:
LAG() provides the previous value and DIF() provides the difference. Make sure to reset it at the first record for each ID.
RETAIN would allow you to keep the value across rows, this will be necessary if you're trying to find the date difference from the first date.
@crimsonpa2009 wrote:
Greetings!
I'm looking for some assistance in calculating the amount of time between multiple dates by subject id and time point in a long formatted data set. An example of the data format is below:
ID Completed Date Timepoint Time 1 2/19/2018 1 0 1 2/20/2018 2 1 2/21/2018 3 2 2/13/2018 1 0 2 2/14/2018 2 2 2/15/2018 3 3 2/15/2015 1 0 3 2/16/2015 2 Thanks in advance for your assistance!
v/r,
Torrance
this Q has been asnwered previously?: https://communities.sas.com/t5/General-SAS-Programming/Months-Between-two-dates/td-p/171655
Could you show some example data where the expected amount of time would be something else than zero?
Basically I would like the new time variable for timepoint 1 to be coded as zero; however, each subsequent time should be the difference between date associated with timepoint 2 or timepoint 3 and timepoint 1.
so the final output should as follows:
ID | Completed Date | Timepoint | Time(days) |
1 | 2/19/2018 | 1 | 0 |
1 | 2/20/2018 | 2 | 1 |
1 | 2/21/2018 | 3 | 2 |
2 | 2/13/2018 | 1 | 0 |
2 | 2/14/2018 | 2 | 1 |
2 | 2/15/2018 | 3 | 1 |
3 | 2/15/2015 | 1 | 0 |
3 | 2/16/2015 | 2 | 1 |
Why is feb 15, for id=2, based on the second rather than the first record for that id?
Art, CEO, AnalystFinder.com
retain baseline;
if timepoint=1 then baseline=completed_date;
else time = completed_date - baseline;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.