Only some numerics can be converted to SAS dates directly right? Such as, mmddyy, 040609? You can use format mmddyy8.
But there are special cases where you can't convert them directly and need to go through an extra step rgith? Such as, yyyymmdd, 20090406? You have to convert 20090406 to character using put then convert it to date right?
I just want to make sure if I understand this correctly. Conclusion is that only some numerics can be converted to SAS date directly?
Sure, you can convert any -NUMBER- to a SAS date or SAS date/time value, as long as that number either
1) represents the number of days from Jan 1, 1960 (so the number -3334 represents Nov 15, 1950 and the number 3334 is Feb 16, 1969 and the number 18216 is Nov 15, 2009)
2) represents the number of seconds from midnight Jan 1, 1960 (date/time value)
However, a NUMERIC variable value like this: 19501115 or a character variable value like this: '19501115' does NOT represent the number of days from Jan 1, 1960 -- so it must be converted from being a number or a character string so that SAS recognizes it as a date variable value and correctly stores your date value as the number of days since Jan 1, 1960.
So when you say "any" numeric, I have to say that the answer is, yes, if you understand SAS date/time values and SAS date/time functions.
hm..i think i need to read the section SAS dates again. I need to tell whether if the number is a qualified number or a number that I need to convert to characters first. Also, Cynthia, how can you be so good with SAS? I see that you reply pretty much every thread here. How can you know everything about SAS? That's amazing! Any book recommendations? Thanks!
Thanks for the compliment. Long ago, (in a galaxy far, far away) I was a Literature student who discovered that there were no good jobs for someone who could deconstruct Faulkner, Melville, Wallace Stevens and T. S. Eliot. And, so I aimed myself at a programmer trainee job; learned Fortran, Cobol, JCL SAS and Easytreve.
But SAS was actually the very first programming language I learned, before the programmer trainee job even started. So when I got the opportunity to be a "real" programmer, one of my choices was to work in the Cobol side of the shop or the "ad-hoc" SAS side of the shop. I chose working on the SAS side of things and have been using SAS ever since.
So it's been a very, -very- long time that I have worked with SAS. I don't know "everything" about SAS -- but I do know how to look things up in the documentation. And, there's the whole puzzle aspect of solving a problem that I find appealing.
My students all speak highly of these authors: Cody, Carpenter, Delwiche/Slaughter, Burlew and Haworth. But there are many other good books available on different topics (For example, I don't teach Stat classes, so I don't know what Stat-related books are most useful.)
The best advice I can give you is learn how to use the resources on support.sas.com -- the search facility, the documentation, the samples and the repository of SAS Global Forum papers. And, don't be afraid to ask yourself "what if" questions and test out your theories or ideas in a test program on sample data.
Thank you for the inputs and advices. I will definitly look into these resources. But I think I should read a few SAS books again just to get a better understanding on everything. I went through both the BASE and ADVANCED SAS certification exam and I feel at the end I remembered and learned nothing. I keep getting stuck on small problems. This just makes me sad. It is like spending so much time and effort and at end you got nothing from it. I have been a SAS programmer for a year and half now and I feel that my skills on SAS did not improve at all. Ok, i need to stop whining and start reading and check on these resources. Thanks again!
to import a YYYYMMDD-style integer into a sas date value, i use the ND8601DA. informat and apply the date9. format. YYYYMMDDHHMMSS-style integer into a sas datetime value, one can use the ND8601DT. informat and apply the datetime19. format.