yydddhhmm julian date/time compare

Reply
Contributor
Posts: 23

yydddhhmm julian date/time compare

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 ?

Thanks,

Stephen

Super User
Posts: 19,771

Re: yydddhhmm julian date/time compare

What's your starting year? 1900?

Contributor
Posts: 23

Re: yydddhhmm julian date/time compare

Not sure what you are asking - all dates will be from > 2000;

Super User
Posts: 19,771

Re: yydddhhmm julian date/time compare

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.

data have;

informat start end $9.;

input Process Start $  END $;

datalines;

1 141540354 141540448

2 141542300 141550130

;

run;

data want;

set have;

date_start=input(substr(start, 1, 5), julian7.);

date_end=input(substr(end,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.;

run;

Contributor
Posts: 23

Re: yydddhhmm julian date/time compare

Thank you VERY much - it is greatly appreciated and does the job!

Stephen

Respected Advisor
Posts: 4,919

Re: yydddhhmm julian date/time compare

Are your dates numbers or strings? - PG

PG
Ask a Question
Discussion stats
  • 5 replies
  • 259 views
  • 0 likes
  • 3 in conversation