Hi, so I was importing XLSX file with script below:
Converted into date only in SAS with yymmdd format:
Anyone has solution on how to get the field into datetime original?
In Excel, there is no difference between dates and times on a technical level. Dates are stored as integers, while times are always stored as fraction of a day, so a date can always be considered a datetime with a time part of 00:00:00.
If PROC IMPORT finds only integers (and a date-only format like you show), it will assume this to be a pure date column.
To make these datetime in SAS, do
start = dhms(start,0,0,0);
end = dhms(end,0,0,0);
format start end e8601dt19.; /* or any other format you like */
Alternatively, multiply the values by 86400 (number of seconds in a day). This would also keep "hidden" time parts.
In Excel, there is no difference between dates and times on a technical level. Dates are stored as integers, while times are always stored as fraction of a day, so a date can always be considered a datetime with a time part of 00:00:00.
If PROC IMPORT finds only integers (and a date-only format like you show), it will assume this to be a pure date column.
To make these datetime in SAS, do
start = dhms(start,0,0,0);
end = dhms(end,0,0,0);
format start end e8601dt19.; /* or any other format you like */
Alternatively, multiply the values by 86400 (number of seconds in a day). This would also keep "hidden" time parts.
The DHMS() function will also keep the fractions from the DATE value passed to it.
6 data test;
7 date=datetime()/'24:00't;
8 dt=dhms(date,0,0,0);
9 put date=comma20.2 date=date9. dt=datetime19.;
10 run;
date=23,457.40 date=22MAR2024 dt=22MAR2024:09:33:13
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.