DATA Step, Macro, Functions and more

Question about datetimes and precision

New Contributor
Posts: 3

Question about datetimes and precision

Can someone explain where the highest precision numbers in variables d4 to d7 came from?

The SAS program:

data foo;
format d1-d7 datetime30.6;
timestring = "23:59:59.997000000";
time = input(timestring,time18.);
d1 = dhms(0,0,0,time);
d2 = dhms('08DEC1981'd,0,0,time);
d3 = dhms('31DEC2503'd,0,0,time);
d4 = dhms('31DEC2504'd,0,0,time);
d5 = dhms('08DEC2981'd,0,0,time);
d6 = dhms('08DEC4981'd,0,0,time);
d7 = dhms('08DEC9999'd,0,0,time);
proc print;run;

The output:

Obs d1 d2 d3

1 01JAN1960:23:59:59.997000 08DEC1981:23:59:59.997000 31DEC2503:23:59:59.997000

Obs d4 d5 d6

1 31DEC2504:23:59:59.997002 08DEC2981:23:59:59.997002 08DEC4981:23:59:59.996994

Obs d7 timestring time

1 08DEC9999:23:59:59.997009 23:59:59.997000000 86400.00
Super Contributor
Super Contributor
Posts: 3,176

Re: Question about datetimes and precision

Posted in reply to MichielBorkent
You can do this by using the BEST. format -- also, the LENGTH statement has influence on granularity, as where the FORMAT statement influences the output format being displayed. As well, the higher the date, the larger integer portion of the SAS variable occurs. Also, the SAS OS platform has some influence. Suggested links for reading provided below.

Scott Barry
SBBWorks, Inc.

SAS 9.2 Language Reference: Concepts - Numeric Precision in SAS Software:

SAS 9.2 Language Reference: Concepts - About SAS Date, Time, and Datetime Values

Step-by-Step Programming with Base SAS(R) Software - Working with Numeric Variables:
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation