BookmarkSubscribeRSS Feed
dhrums28
Calcite | Level 5

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

 

4 REPLIES 4
art297
Opal | Level 21

Depends! Does 1942 represent 7:42pm?

 

Art, CEO, AnalystFinder.com

Jagadishkatam
Amethyst | Level 16

 

 

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
PGStats
Opal | Level 21
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
BrunoMueller
SAS Super FREQ

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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