SAS informat datetime milliseconds

与世无争的帅哥 提交于 2019-12-11 09:16:40

问题


Can SAS store and use datetimes that contain fractions of less than 1/10th of a second?

eg:

data _null_;
input @1 from_dt:datetime22.;
put from_dt= ;
cards;      
24Sep2009:11:21:19.856
;
run;

回答1:


A datetime variable is a numeric variable just like any other numeric variables. We just understand its value as the seconds since 01jan1960T00:00:00. Hope this helps.

data _null_;

  /* for date time, 1 means 1 sec since midnight jan 1st 1960 */
  dt = 1;
  put dt :datetime.;

  /* you can show the hundredth of second using datetime format */
  dt = 0.01;
  put dt :datetime19.2;

  /* but it is just a double type number. you can do
     what you want with the variable as with any other numeric
     variables */
  dt = 0.01;
  put "It was " dt :wordf15. "second after midnight.";
run;
/* on log
01JAN60:00:00:01
01JAN60:00:00:00.01
it was zero and 01/100 second after midnight.
*/



回答2:


Your sample code is rounding on the printed output. Adding a format (eg best32.) on the put statement shows that there is better precision being held...

data _null_; 
input @1 from_dt:datetime22.; 
put from_dt= best32.; 
cards;
24Sep2009:11:21:19.856 
; 
run; 

from_dt=1569410479.856



回答3:


As Rog pointed out, you can read in and store datetimes with more precision than .1 sec.

Just use the datetime22.3 or a similar format and informat instead of datetime22.



来源:https://stackoverflow.com/questions/1471229/sas-informat-datetime-milliseconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!