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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.