DATA Step, Macro, Functions and more

What is the informat for date and time field

Reply
Frequent Contributor
Frequent Contributor
Posts: 81

What is the informat for date and time field

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.

Respected Advisor
Posts: 4,932

Re: What is the informat for date and time field

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
Frequent Contributor
Frequent Contributor
Posts: 81

Re: What is the informat for date and time field

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

Frequent Contributor
Frequent Contributor
Posts: 81

Re: What is the informat for date and time field

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

Super User
Posts: 10,044

Re: What is the informat for date and time field

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

Respected Advisor
Posts: 3,799

Re: What is the informat for date and time field

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
;
Frequent Contributor
Frequent Contributor
Posts: 81

Re: What is the informat for date and time field

Posted in reply to data_null__

Thanks very much Ksharp and data _null_.

Both is working to me.

Thanks very much.

Doney

Ask a Question
Discussion stats
  • 6 replies
  • 818 views
  • 6 likes
  • 4 in conversation