Tunde Awosanya
Tunde Awosanya

Reputation: 365

Reading custom date time formats with SAS

I have a comma delimited data set whose first 2 rows is like this:

1/13/2010 21:09,3.3
11/30/2010 7:33,7.2
....

In trying to read the data in SAS, I have done this data step below:

data myDataSet;
     infile      'sampleData.csv'    dlm=',';
     input     timestamp     :mmddyy16.     value;
run;

Now that the data is now a SAS data set, I try to view it by doing:

data viewData;
     set     myDataSet;
     format     timestamp     date9.;
run;
proc     print     data=viewData;
run;

I observed that the timestamp column output only contains the date and not with the time. I want the timestamp to be read and displayed in a format like "dd-mm-yyyy HH:MM:SS". How do I ensure that in reading the file, the informat is correctly specified and no component of the timestamp is lost?

Upvotes: 1

Views: 517

Answers (1)

Joe
Joe

Reputation: 63424

MMDDYYw is a date informat, not a datetime informat - it only reads days and larger and ignores the time. It has a practical maximum length of 10 (although it allows up to 32) as a result.

You can use MDYAMPM. to read those two dates in, among other informats. That might be the ultimately correct informat, or it might not, depending on the totality of your data; several NLS specific informats might also work. See the SAS informat documentation for more details.

Upvotes: 0

Related Questions