06-06-2014 01:19 PM
I have tried for 2 days reading documentation and trying various formats to no avail.
I am trying to compare to records and come up with how long the process took to run.
I have 2 records with date - timestamps in the following format: YYDDDHHMM
Sample data :
141540354 (rec1) 141540448 (rec 2) desired output = time it took to execute 00:54 hours/minutes execution
141542300 (rec 1) 141550130 (rec 2) 2 different julian dates - execurtion time = 02:30 hours/minutes execution
Does SAS have any functions to compare julian dates/times ?
06-06-2014 01:56 PM
Here's an inelegant solution that uses the fact that SAS will read in Julian Dates. So I separate out the date part to get the date and then read in the time separately which needs to be in the format 12.46 (12 hours 46 minutes). There's probably an easier way to do the time, but I'll leave that to you.
Then I convert both to date time by using the fact that SAS stores dates as the number of days from January 1, 1960 while datetimes are stored in seconds from January 1, 1960. Converting the date to datetime is then done by multiplying by 24hours*60 minutes*60 seconds = 86400. This could also be done by using the dhms function, as show in dt_start2 dt_end2.
informat start end $9.;
input Process Start $ END $;
1 141540354 141540448
2 141542300 141550130
date_start=input(substr(start, 1, 5), julian7.);
time_start=input(catx(".", substr(start, 6, 2), substr(start, 8)), time10.);
time_end=input(catx(".", substr(end, 6, 2), substr(end, 8)), time10.);
duration=(date_end*86400+time_end) - (date_start*86400+time_start);
dt_start2=dhms(date_start, input(substr(start, 6, 2), 2.), input(substr(start, 8), 2.), 0);
dt_end2=dhms(date_end, input(substr(end, 6, 2), 2.), input(substr(end, 8), 2.), 0);
duration2 = dt_end2-dt_start2;
format dat: date9. time: duration: time5. dt: datetime21.;