New Contributor
Posts: 3

Start Date and Time - stop date time

i have dataset with charater SAS date and time as below:

SRTDT-START DATE

PSTTM- START TIME

STPDT-STOP DATE

PEDTM-END TIME

SRTDT         PSTTM           STPDT             PEDTM

20150211     1942               20150212         0030

20130826     1220               20130826         1535

I am trying to calculate the whole procedure time in minute. any suggestions !

thanks,

D

PROC Star
Posts: 8,164

Re: Start Date and Time - stop date time

Depends! Does 1942 represent 7:42pm?

Art, CEO, AnalystFinder.com

Posts: 1,147

Re: Start Date and Time - stop date time

``````data have;
input SRTDT\$         PSTTM\$           STPDT\$             PEDTM\$;
cards;
20150211     1942               20150212         0030
20130826     1220               20130826         1535
;

data want;
set have;
shr=input(SUBSTR(strip(PSTTM), 1,2),best.);
smi=input(SUBSTR(strip(PSTTM), 3,2),best.);
ssec=coalesce(input(SUBSTR(strip(PSTTM),5,2),best.),0);
sday=input(strip(SRTDT),yymmdd10.);

ehr=input(SUBSTR(strip(PEDTM), 1,2),best.);
emi=input(SUBSTR(strip(PEDTM), 3,2),best.);
esec=coalesce(input(SUBSTR(strip(PEDTM),5,2),best.),0);
eday=input(strip(STPDT),yymmdd10.);

startdate=dhms(sday,shr,smi,ssec);
stopdate=dhms(eday,ehr,emi,esec);

diff=intck('minute',startdate,stopdate);
format startdate stopdate datetime20.;

run;

proc print;
run;``````
Thanks,
Jag
Posts: 5,532

Re: Start Date and Time - stop date time

``````data have;
input SRTDT \$ PSTTM \$ STPDT \$ PEDTM \$;
datalines;
20150211     1942               20150212         0030
20130826     1220               20130826         1535
;

data want;
set have;
strt = dhms(
input(srtdt,yymmdd8.),
input(substr(psttm,1,2), 2.),
input(substr(psttm,3,2), 2.), 0);
endt = dhms(
input(stpdt,yymmdd8.),
input(substr(pedtm,1,2), 2.),
input(substr(pedtm,3,2), 2.), 0);
minutes = intck("minute", strt, endt);
format strt endt datetime15.;
run;``````
PG
SAS Super FREQ
Posts: 825

Re: Start Date and Time - stop date time

Hi

SAS does have the HHMMSS. informat which can read either hh:mm:ss or hhmmss time values, together with the YYMMDD. informat you can convert the char values to SAS date and time values, the DHMS will make a datetime value out of it.

``````data have;
input SRTDT \$ PSTTM \$ STPDT \$ PEDTM \$;
psttm2 = input(psttm, hhmmss4.);
srtdt2 = input(srtdt, yymmdd8.);

startDate = dhms(srtdt2,0,0,psttm2);
format
psttm2 time8.
srtdt2 date9.
startDate datetime19.
;
datalines;
20150211     1942               20150212         0030
20130826     1220               20130826         1535
;``````

Bruno

Discussion stats
• 4 replies
• 176 views
• 0 likes
• 5 in conversation