I have a date from a dataset called
delivery_date. It defaults to 01jan1900.
I inserted a datepart(delivery_date) format=mmddyy10.; It then defaults to 01/01/0000
It will not provided the correct date from the dataset.
What do you mean by "defaults"?
Once you have an observation in a dataset the value is the vlaue. Defaults have nothing to do with it.
What is the TYPE of the variable? Is it numeric of character (SAS only has those two variable types). If character what is its storage length? Storage length for numeric is less important.
Does it have a FORMAT specification attached to it? For example for a number to print with a value like 1/1/1900 it would need to have the a format like MMDDYY10. or DDMMYY10. attached to it. If it prints like 01JAN1900 then it might have the DATE9 format attached to it.
Note that taking the DATEPART() of a value that is already a date should just give you 01JAN1960 since all the DATEPART() function does is divide the current value by the number of seconds in day to get a value days instead of seconds.
The only date I am aware of that defaults to 1/1/1900 is someone using the earliest date that Microslop office products use.
If the "date" actually is 1/1/1900 then "datepart" will not return the value you show in a SAS dataset.
38 39 data example; 40 x='01Jan1900'd; 41 format x mmddyy10.; 42 dp = datepart(x); 43 put x= mmddyy10.; 44 put dp = mmddyy10. dp= best6.; 45 run; x=01/01/1900 dp=12/31/1959 dp=-1
If the "date" is yet another example of a sloppy description that is actually a datetime value that someone calls a date, a way to common practice in some circles that use datetime values but never actually have a time component and everything is 12:00:00AM, then you still don't get that result unless you are doing something very peculiar:
data example; x='01Jan1900:00:00:00'dt; dp = datepart(x); put x= datetime20.; put dp = mmddyy10. dp= best6.; run;
If you are exporting date, time or datetime values to Excel and expect them to look correct then that is an issue all by itself as Excel will look at values and make choices about displaying them.
Note: The only way I have ever gotten a SAS date value to display a 4 digit year of 0000 is with a picture format that is set to hide actual years and only displays the month and day of month. The year "0000" is way before the earliest valid dates SAS will work with in the 1580s. If you try to create or display a value with year 0000 it will not unless you have a very custom format like the one I just mentioned.
data example; x= '01Jan1600'd; do i=-1 to -30 by -1; y= intnx('year',x,i); put i= x= mmddyy10. y= mmddyy10.; output; end; run;
Shows what happens trying to create year values before 1582.
In some cases it appears that SAS can treat a year of '0' as the 2 digit year implied from the YEARCUTOFF option and might treat the value as year 2000 (0000=00 =>2-digit representation of 2000 if yearcutoff > 1900)
So, you need to go into much more excruciating detail of exactly what the value looked like in the native file before reading into SAS, the value afterwards without a format and what the assigned format is after reading into SAS and how you are looking at it to see "01/01/0000".
Post
It is a real pity and a PITA that we have to tell you this AGAIN AND AGAIN.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.