I have a numeric date with time and I need to convert just the datepart into yyyy-mm-dd format.
data (numeric):
RFSTDT
16DEC2020:00:00:00.000
want (numeric):
NEW_RFSTDT
2020-12-16
As you hinted, you need to use the datepart() function to convert a SAS datetime to a SAS date.
To display that date as you want, use the yymmddd10. format.
Use the DATEPART function as documented here: DATEPART
data _null_;
RFSTDT = '16DEC2020:00:00:00.000'dt;
NEW_RFSTDT = datepart(RFSTDT);
format RFSTDT datetime22.3 NEW_RFSTDT yymmddd10.;
put _all_;
run;
You also asked the same question here: https://communities.sas.com/t5/SAS-Programming/convert-numeric-date-to-another-format/td-p/707137
and you got the same answer. Why the repeat?
As you hinted, you need to use the datepart() function to convert a SAS datetime to a SAS date.
To display that date as you want, use the yymmddd10. format.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.