BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gil_
Quartz | Level 8
I have a table where the datetime firld is formats

23Sep18:11:32:00. Which is datetime 16

I need that field to be formatted as a character.

Like this
23Sep18:11:32:00
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data test;
informat dt datetime16.;
format dt datetime16.;
dt="23Sep18:11:32:00"dt;
dtChar=put(dt, datetime16.);
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20
data test;
informat dt datetime16.;
format dt datetime16.;
dt="23Sep18:11:32:00"dt;
dtChar=put(dt, datetime16.);
run;
Tom
Super User Tom
Super User

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;

 

data_null__
Jade | Level 19
I would recommend it you are converting a SAS date-time to character to use a format that will sort like one of the ISO8601 formats.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 15475 views
  • 3 likes
  • 4 in conversation