data citiday(keep=SNYDJCM date); set sashelp.citiday; if date <="28feb1988"d; format date datetime.; /*format date datetime20.1;*/ run;
/*01JAN60:02:50:27 using datetime.
prefer to get the actual datetime not 1960
Ieally I want the date in mmddyy10 with the timestamp
however I can settle for the date9 format with the timestamp*/
Dates in SAS are measured in days, time and Datetimes in seconds. So if you apply a datetime format to a date value you typically get something in 1960 or so as the number days is short by about 60*60*24 .
If you want a date time for the date use the DHMS function:
dt = dhms(date,0,0,0);
and apply the datetime format to the DT variable.
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
Your code IS showing the actual date. You gave it a number of seconds that was under 3 hours into the first day of 1960 so it is properly showing the date as the first of January in 1960. SAS stores dates as number of days since 1960 and datetime values as number of seconds since 1960.
If you want the DATETIME of execution use the DATETIME() function.
I don't recommend displaying dates in either MDY or DMY order, either one will confuse 50% of your audience. Either use YMD order of d-MON-y.
312 data now;
313 today = date();
314 now = datetime();
315 put 'TODAY ' / today comma12. / today date9. / today yymmdd10. / today mmddyy10. / today ddmmyy10.
316 // 'NOW ' / now comma17. / now datetime19. / now mdyampm. / now e8601dt.
317 ;
318 run;
TODAY
22,629
15DEC2021
2021-12-15
12/15/2021
15/12/2021
NOW
1,955,222,463
15DEC2021:21:21:03
12/15/2021 9:21 PM
2021-12-15T21:21:03
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.