data test;
informat dt datetime16.;
format dt datetime16.;
dt="23Sep18:11:32:00"dt;
dtChar=put(dt, datetime16.);
run;
data test;
informat dt datetime16.;
format dt datetime16.;
dt="23Sep18:11:32:00"dt;
dtChar=put(dt, datetime16.);
run;
Note that formats are instructions for how to convert values into character strings for display purposes.
Sounds like you want to create a new VARIABLE that is character instead of numeric.
data want ;
set have ;
length char_date $16 ;
char_date = put(real_date,datetime16.);
run;
I would highly recommend not using a format that does not display the century for dates.
Note that there is bug (feature?) of the DATETIME format that makes it not use 4 digit years when use a width of 18. So use a width of 19 instead and add the -L format option or LEFT() function call to remove the leading space.
data want ;
set have ;
length char_date $18;
char_date = put(real_date,datetime19.-L);
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 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.