正确命令在SAS中输入YYYY-mm-dd hh:mm:ss'

时间:2012-11-21 02:10:27

标签: sas

我有csv格式的数据,并带有这种格式的特定时间戳字段:

'2009-07-30 20:50:19'

如何将其读入SS数据集?我一直在尝试这个,但无济于事。

             data filecontents;
             infile       "C:\es.txt" dlm=',' MISSOVER DSD firstobs=2 lrecl=32767 ;
             input  START_TIME :ANYDTDTM. 
             FORMAT START_TIME datetime.

感谢。

1 个答案:

答案 0 :(得分:4)

对我来说似乎很好。以下代码适用于我的机器(9.3 TSM2)。你怎么了?您是否只是在输入语句(您的示例代码是)之后缺少分号?

data test;
infile "c:\temp\test.csv" dlm=',' missover;
input 
    dtvar :YMDDTTM.
    var1 $
    var2 $;
format dtvar DATETIME19.;
put dtvar= DATETIME19.;
run;

结果:

608  data test;
609  infile "c:\temp\test.csv" dlm=',' missover;
610  input
611      dtvar :YMDDTTM.
612      var1 $
613      var2 $;
614  format dtvar DATETIME19.;
615  put dtvar= DATETIME19.;
616  run;

NOTE: The infile "c:\temp\test.csv" is:
      Filename=c:\temp\test.csv,
      RECFM=V,LRECL=256,File Size (bytes)=31,
      Last Modified=20Nov2012:20:20:51,
      Create Time=20Nov2012:20:17:51

dtvar=30JUL2009:20:50:19
NOTE: 1 record was read from the infile "c:\temp\test.csv".
      The minimum record length was 29.
      The maximum record length was 29.
NOTE: The data set WORK.TEST has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds

对于它的价值,YMDDTTMw.d是具体的信息(ANYDTDTM。当然也会有用)。