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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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