Hi:
To me, the question is what are you really trying to do, or what is your purpose for treating the date as a "raw" number????
For example, the date, 12/10/2005 or 10Dec2005 or 20051210 -- can be represented many different ways, but no matter which representation we choose, it ALWAYS means the 10th of December 2005. 20051210 depends on context for meaning.
So, if "20051210" looked like any of these numbers, with punctuation added, then none of us would immediately think of Dec 10th 2005 as the meaning for the number.
$200,512.10 or
200-51-210
20,051,210
20.051.210
200.512,10
SAS stores a date as a number on a timeline -- if Jan 1, 1960 is "day 0" on the timeline, then Dec 10th 2005 represents 16780 days FROM Jan 1, 1960. And, since there were days BEFORE Jan 1, 1960, the SAS internal timeline allows for dates to go back to the 1500's. But let's just take one date, for example, Nov 15th 1950 was 3334 days BEFORE Jan 1, 1960 so the internal number for that date is -3334. The internal number for Dec 10th 2005 is 16780; the internal number for
Dec 10th 2999 is 379831; the internal number for Dec 10th 1600 is -131143. I think that's pretty cool how SAS stores dates in this fashion.
Once your date is stored as that "timeline version" of the number, there is no ambiguity about what the number can mean inside SAS when the variable is used. For example, let's say I want to find out how many days it's been between Dec 10th 2005 and today (July 16th 2008), I can do something like this in SAS:
[pre]
elapsed = today() - datevar;
elapsed = 17729 - 16780; <----what SAS does internally
elapsed = 949 = almost 3 years which is the right number of days
VERSUS
20080716 - 20051210 = 29506???? this is a meaningless number
[/pre]
But, that subtraction only works IF the dates are stored as their timeline versions of the number. As you can see, subtracting the 8 digit version of the number does not accurately reflect the correct number of elapsed days.
If it's annoying to see 16780 or -3334, when you want to see dates, the solution is very simple -- just assign a permanent format (such as mmddyy10. or yymmddn8.) to the date variable. Most SAS procedures will use a permanently assigned format to display a date value. If you want to change the displayed value for a date, you can change the permanent format by using a different format. So the same timeline version of the dates can be displayed different ways without affecting how SAS will be able to use them internally:
[pre]
format to -- Display As --
use -3334 16780
mmddyy10. 11/15/1950 12/10/2005
year4. 1950 2005
monyy7. NOV1950 DEC2005
date9. 15NOV1950 10DEC2005
[/pre]
Do you really want Dec 10th 2005 to be to be internally stored as the number, 20051210 (20 milltion, 51 thousand, Two-hundred and 10)?? It will make your unformatted date easy to read, but will pretty much render the value useless for calculating how long or how old or elapsed time.
cynthia