BookmarkSubscribeRSS Feed
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7

Hi Dear,

I want to read this below two dates and have to find the total time difference between these below dates.( I mean how  long it took from date1 to date2: want to know hour, min, and sec); What is the informat that  I have to use and what the SAS function will return  the difference.between date1 and date2 in Hour , Min and Sec.

Date1                                                        Date2

2012-04-18 18:21:48.463           2012-04-20 22:06:46.753


Thanks for your help in advance.

Dony.

6 REPLIES 6
PGStats
Opal | Level 21

Like this :

data test;

informat d1 d2 ANYDTDTM.;

input d1 & d2 &;

dif = d2-d1;

format dif time14.3;

put dif=;

datalines;

2012-04-18 18:21:48.463           2012-04-20 22:06:46.753

;

PG

PG
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7

HI PGStats.

Thanks very much for this great help, That works fine. but Just one more question. : How do I reformat d1 and d2.

Thanks very much for your help again.

Dony

Inp
Obsidian | Level 7 Inp
Obsidian | Level 7

Thanks PGStats.

The below solution works on SAS 9.2 but I have to code the below is in SAS 8.2. Is there any equivalent informat avaialble in SAS 8.2? but I got error messge

 

ERROR 48-59: THE INFORMAT ANYDTDTM WAS NOT FOUND OR COULD NOT BE LOADED

data test;

informat d1 d2 ANYDTDTM.;

input d1 & d2 &;

dif = d2-d1;

format dif time14.3;

put dif=;

datalines;

2012-04-18 18:21:48.463           2012-04-20 22:06:46.753

Ksharp
Super User

I don't know whether your SAS 8.2 has function DHMS() .

data test;
input d1 : yymmdd10. t1 : time20. d2 : yymmdd10. t2 : time20.;
dd1=dhms(d1,0,0,t1); dd2=dhms(d2,0,0,t2);
dif = dd2-dd1;
format dif time14.3;
put dif=;
datalines;
2012-04-18 18:21:48.463           2012-04-20 22:06:46.753
;
run;

Ksharp

data_null__
Jade | Level 19

YMDDTTM informat should work in your 8.2

http://support.sas.com/kb/15/803.html

data test;
   informat d1 d2 YMDDTTM24.;
  
input d1 & d2 &;
   dif = d2-d1;
  
format dif time14.3 d1 d2 datetime.;
  
put dif=;
   datalines;
2012-04-18 18:21:48.463           2012-04-20 22:06:46.753
;
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7

Thanks very much Ksharp and data _null_.

Both is working to me.

Thanks very much.

Doney

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2610 views
  • 6 likes
  • 4 in conversation