Hello, I'm trying to reformat a date (ddmmmyyy) to DATETIME. The code I tried to use didn't work:
data WORK.DEMOS1;
set WORK.DEMOS;
DateofBirth1=input(DateofBirth,date9.);
format DateofBirth1 datetime16.;
run;
Does anyone know how to do this in a data step or proc sql step? Thanks!
You cannot "reformat" a date to a datetime. You need to convert the date value (number of days) to a datetime value (number of seconds). Then you can use any of the many datetime formats to change how the number is displayed. You must pick a time of day for the datetime value. Most people use midnight (00:00:00).
data WORK.DEMOS1;
set WORK.DEMOS;
DateTimeofBirth=dhms(DateofBirth,0,0,0);
format DateTimeofBirth datetime20.;
run;
Note: Do not display date or datetime values with only 2 digits for the year.
You cannot "reformat" a date to a datetime. You need to convert the date value (number of days) to a datetime value (number of seconds). Then you can use any of the many datetime formats to change how the number is displayed. You must pick a time of day for the datetime value. Most people use midnight (00:00:00).
data WORK.DEMOS1;
set WORK.DEMOS;
DateTimeofBirth=dhms(DateofBirth,0,0,0);
format DateTimeofBirth datetime20.;
run;
Note: Do not display date or datetime values with only 2 digits for the year.
/*If DateofBirth is charatcer*/
data WORK.DEMOS1;
set WORK.DEMOS;
DateofBirth1=dhms(input(DateofBirth,date9.),0,0,0);
format DateofBirth1 datetime16.;
run;
/*If DateofBirth is numeric sas data*/
data WORK.DEMOS1;
set WORK.DEMOS;
DateofBirth1=dhms(DateofBirth,0,0,0);
format DateofBirth1 datetime16.;
run;
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 save with the early bird rate—just $795!
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.