Help using Base SAS procedures

Problem encountered with MDYAMPM

Occasional Contributor
Posts: 10

Problem encountered with MDYAMPM

I am reading a txt delimited file.

Sample data:
Created Date
12/2/2011 7:59:40 AM
13/02/2011 8:02:45 AM

Currently using informat MDYAMPM30.
There is no problem reading the 1st observation and outputs fine. But 2nd observation outputs as nothing.

Sample output :
12/2/2011 7:59:40 AM
Trusted Advisor
Posts: 1,403

Re: Problem encountered with MDYAMPM

Hi Zoey,

I noticed that you are using the MDYAMPM30. informat and as record number 2 in your text file has a month=13 that is causing the output to be missing as the informat doesn't match the data value in your text file (also there would have been a note written to the log file to indicate such).

So depending on whether this was a typo and should be 03 or perhaps in fact the date layout is DDMMYYYY rather than MMDDYYYY then what you are doing is correct or you may need to change the way you read in your data.

If you find that your date layout is in fact DDMMYYYY and you want a datetime field then as there seems to be no DMYAMPM. informat then my suggestion would be to read in the 2 fields as separate date and times and then create a datetime variable... I have written some sample code here if that helps:

data timeDataset(drop=date time);
input datetime1 mdyampm30. @1 date ddmmyy10. time time10. ;
12/2/2011 7:59:40 AM
13/02/2011 8:02:45 AM
10/02/2011 8:02:45 AM

In the code above I am still reading in the field using the informat that you have specified and you may notice that I have added a 3rd record where the value is able to be read in correctly as the month=10 for them mdyampm30 informat or day=10 for the ddmmyy10 informat.

The datetime values in the resulting dataset will obviously be different as the date is being read in differently.

So you just need to work out what structure is your date field is it DDMMYYYY or MMDDYYYY. for your code to read in the data correctly.

I hope this helps.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation