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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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