user971580
user971580

Reputation:

Proper command to input YYYY-mm-dd hh:mm:ss' in SAS

I have data in csv format with a certain timestamp field in this format:

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

How can I read that into a SS dataset? Ive been trying this, but to no avail.

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

Thanks.

Upvotes: 2

Views: 7988

Answers (1)

Joe
Joe

Reputation: 63424

Seems fine to me. The below code works on my machine (9.3 TSM2). What happens for you? Are you just missing a semicolon after the input statement (your example code is)?

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

result:

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

For what it's worth, YMDDTTMw.d is the specific informat for that (ANYDTDTM. will work as well of course).

Upvotes: 4

Related Questions