Simple Date Informat Question

Accepted Solution Solved
Reply
Super Contributor
Posts: 418
Accepted Solution

Simple Date Informat Question

Hello everyone. this is likely a very stupid question, but I cannot figure out why this is happening.

Basically I have a datafile which has dates in the format YYYYMMDD  so 20130110  for October 1st 2013.

If I read it in with an informat of YYMMDD8.  it works, however if I also read it in with the informat of YYMMDD10. it works. (noted a different users code doing this and I thought it was an error at first).

I had always thought you needed back-slashes within your dates to allow YYMMDD10. to work with these dates. This appears to not be true, can anyone explain why this is?

Interestingly enough, even if I just specify YYMMDD.  with no distinct value this works... So If I was going to read in a date that was in YYYYMMDD format, but I did not know if it was going to have back-slashes or not, wouldn't I want to always specify the YYMMDD anyways?

Thanks so much!

Brandon


Accepted Solutions
Solution
‎10-09-2013 11:48 AM
Regular Contributor
Posts: 244

Re: Simple Date Informat Question

I hope Oct 01 2013 would be 20131001 for YYMMDD? Using YYMMDD10 will take 10 characters and then attempt to convert using the YYMMDD informat.  So, if you only have 8, it will still work.  If you are reading from a text file and have two unrelated characters following those 8, it will look at those and try to make a date out of that (2013100178 or something) and fail.

View solution in original post


All Replies
Solution
‎10-09-2013 11:48 AM
Regular Contributor
Posts: 244

Re: Simple Date Informat Question

I hope Oct 01 2013 would be 20131001 for YYMMDD? Using YYMMDD10 will take 10 characters and then attempt to convert using the YYMMDD informat.  So, if you only have 8, it will still work.  If you are reading from a text file and have two unrelated characters following those 8, it will look at those and try to make a date out of that (2013100178 or something) and fail.

Super Contributor
Posts: 418

Re: Simple Date Informat Question

I guess the issue i'm having it, how does the system know that ALL of the following variables (all within one column) work for the yymmdd10. information.

20110105

110105

2011-01-05

2011/01/05.

All of these work, even though the second one is a true YYMMDD and the first one is a YYYYMMDD.  the other ones have identifiers within them.

I was always taught that to read in the first one, you would have to specify YYMMDD8. and the third and fourth would require a YYMMDD10. Apparently that's just not the case!

So i'm assuming the system informat has code underneath that says "IF X variable long" then do following.

If x=10 then YYYY_mm_DD (where _ are any given delimiter).

If x=8 then YYYYMMDD  No delimiter.

IF x=6 then YYMMDD.

ENd;
ELSE invalid:

Okay well that's good to know that sas is actually more dynamic that I was originally told (and sas books) say it is.

Thanks (and if my above statments are not correct, please let me know)!

Brandon

Regular Contributor
Posts: 244

Re: Simple Date Informat Question

You should use the informats you mention.  Any other informat length may lead to undesired results, like in my example.  However, SAS is fairly intelligent and tries to make things work out for you even if you don't use the right informat, or if you have a situation where your data is messy and sometimes it is 2001-01-01 and sometimes it is 010101.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 236 views
  • 0 likes
  • 2 in conversation