BookmarkSubscribeRSS Feed
ZoeyElle
Calcite | Level 5
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
.
1 REPLY 1
MichelleHomes
Meteorite | Level 14
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. ;
datetime2=dhms(date,hour(time),minute(time),second(time));
cards;
12/2/2011 7:59:40 AM
13/02/2011 8:02:45 AM
10/02/2011 8:02:45 AM
;
run;

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.

Cheers,
Michelle
http://twitter.com/homesatmetacoda
//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1077 views
  • 0 likes
  • 2 in conversation