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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: