- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to create a report that shows a list of subjects, their date/time of first dose, date/time of last dose, and the difference between the two date/times. I am supposed to report the difference in the format "D Days:HH:MM". In other words, if the first dose date/time was 01JAN2019:08:00 and the last dose date/time was 05JAN2019:09:30, then the result for the difference would say, "4 Days:01:30".
I have been able to use INTNX to get the number of days, but how would I further extract the hours and minutes that has transpired? I think my biggest concern is if the example above had the times swapped: 01JAN2019:09:30 and 05JAN2019:08:00. In this case, the difference should be "3 Days:22:30". I don't think INTNX would produce the proper number of days. It would still return 4.
Here is a sample dataset to help get you started. Any suggestions?
proc sql;
create table have (SUBJECT char(11), MINDTTM num format=datetime18., MAXDTTM num format=datetime18.);
insert into have (subject, mindttm, maxdttm)
values('001-001-001','06DEC2018:07:35:00'dt,'08JAN2019:08:24:00'dt)
values('001-001-002','06DEC2018:07:50:00'dt,'07JAN2019:07:17:00'dt)
values('001-001-003','07DEC2018:08:30:00'dt,'07JAN2019:07:30:00'dt)
values('001-001-004','07DEC2018:08:40:00'dt,'18MAR2019:07:49:00'dt)
values('001-001-005','01JAN2019:08:00:00'dt,'05JAN2019:09:30:00'dt)
values('001-001-006','01JAN2019:09:30:00'dt,'05JAN2019:08:00:00'dt);
quit;
data want;
set have;
daydiff=intck('DTDAY',mindttm,maxdttm);
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just take the difference, which will be a value in seconds. To display it as DAY and HH:MM then split the value using 24Hours.
seconds=maxdttm - mindtdtm;
days=int(seconds/'24:00't);
hhmm=mod(seconds,'24:00't);
string=catx('/',catx(' ',days,'days'),put(hhmm,tod5.));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just take the difference, which will be a value in seconds. To display it as DAY and HH:MM then split the value using 24Hours.
seconds=maxdttm - mindtdtm;
days=int(seconds/'24:00't);
hhmm=mod(seconds,'24:00't);
string=catx('/',catx(' ',days,'days'),put(hhmm,tod5.));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content