12-07-2017 11:11 AM
I need help on SAS datetimes. I always struggle with datetimes in SAS. I need to find a difference of two datetimes and then delete times that are <0 and >60 minutes.
I know how to find the difference, here's ,my sample code. I have two Time variables with datetime1=01OCT17:16:11:30 and datetime2=01OCT17:16:16:50.
Format time1 time2 time.;
Format diff time8.;
If diff <=0 and diff >60 then delete; (I’m having problem here, as it has seconds and the diff variable is not a whole number.)
How can I get the output in 00:30:05 format and delete <0 and >60 minutes and get the 90th percentiles in 00:30:05 format (include minutes and seconds).
12-07-2017 12:02 PM
This is much more easily accomplished with the SAS INTCK function, which is designed to calculate intervals between dates, times or
do datetime1='01JAN2017 00:00:00'dt to '31JAN2017 00:00:00'dt by 24*60*60;
if rand('UNIFORM') > .1 then datetime2=datetime1+rand('NORMAL',3600,500);
else if rand('UNIFORM') > .9 then datetime2=datetime1+72000;
format da: datetime.;
If diff <=0 or diff =>60 then delete;