BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anotherdream
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
snoopy369
Barite | Level 11

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

3 REPLIES 3
snoopy369
Barite | Level 11

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.

Anotherdream
Quartz | Level 8

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

snoopy369
Barite | Level 11

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 486 views
  • 0 likes
  • 2 in conversation