11-12-2015 01:09 PM
I need help (SAS code) in calculating difference in minutes and hours for datetime variables. I have attached a copy of my data.
Here I have several Reg_Nos and the corresponding culture_dates (datetime). Some of the Reg_nos have multiple culture_date which are in different row compared to the first culture_date for that Reg_no (eg. I have highlighted in red).
I need to find the difference in minutes and hours from the first culture_date to the next cultre_date if a Reg_No has more than one culture_date.
Thanks for the help!
11-12-2015 02:02 PM
Note: you'd want to not count the cases where the current reg_no and the previous reg_no don't match, again LAG can help you determine this.
11-13-2015 04:14 AM
Here's a sample code using retain instead of lag.
data reg_no(drop=day row);
do reg_no=1 to 10;
do row = 1 to reg_no;
culture_date= DHMS(day+row,reg_no+row*row,reg_no,0) ;
format culture_date datetime.;
format day ddmmyy.;
retain lastdate firstdate;
format delay time. ;
format delay_since_first time. ;
if first.reg_no then
delay= culture_date - lastdate;
delay_since_first= culture_date - firstdate;