BookmarkSubscribeRSS Feed
crimsonpa2009
Calcite | Level 5

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:  

 

IDCompleted DateTimepointTime
12/19/201810
12/20/20182 
12/21/20183 
22/13/201810
22/14/20182 
22/15/20183 
32/15/201510
32/16/20152 

 Thanks in advance for your assistance!

 

v/r,

 

Torrance 

6 REPLIES 6
Reeza
Super User

It's not clear what you want as output, however, look at:

 

  • LAG() and the DIF() function. 
  • RETAIN

 

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 


 

 

PGStats
Opal | Level 21

Could you show some example data where the expected amount of time would be something else than zero?

PG
crimsonpa2009
Calcite | Level 5

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:

 

IDCompleted DateTimepointTime(days)
12/19/201810
12/20/20182 1
12/21/20183 2
22/13/201810
22/14/20182
22/15/20183 1
32/15/201510
32/16/20152 1
art297
Opal | Level 21

Why is feb 15, for id=2, based on the second rather than the first record for that id?

 

Art, CEO, AnalystFinder.com

 

Reeza
Super User
retain baseline;

if timepoint=1 then baseline=completed_date;
else time = completed_date - baseline;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 6 replies
  • 896 views
  • 0 likes
  • 5 in conversation