BookmarkSubscribeRSS Feed
FLINT
Calcite | Level 5
How to Convert DATETIME19. TO dd/mm/YYYY HH:MM:SS in Sas select
4 REPLIES 4
Kurt_Bremser
Super User

You can create a custom picture format with proc format.

 

But personally, I would advise to follow the ISO standards and use one of the e8601 formats provided by SAS OOTB.

FLINT
Calcite | Level 5
Please help me with some sample text.I want to convert 03AUG2018:18:09:18
to
03/08/2018 18:09 .this is one of the values in column
ballardw
Super User

@FLINT wrote:
Please help me with some sample text.I want to convert 03AUG2018:18:09:18
to
03/08/2018 18:09 .this is one of the values in column

There is no "conversion". Display formats are only rules for how a value  is displayed. And the value must be correct. To change a TEXT value you either 1) create an actual numeric datetime value and use an appropriate format or 2) Write lots of ugly code to parse and put pieces together. An INPUT with the correct INFORMAT and a Put statement would possibly be acceptable. Most of the time is really a much better idea to create a date or datetime variable as then there are many more options on manipulation and display.

 

proc format library=work;
picture dtfixed 
low-high = '%0m/%0d/%Y %0H:%0M:%0S'  (datatype=datetime)
;
run;

data _null_;
   x=input('15Feb2017:01:09:13',datetime18.);
   put x=  dtfixed. x= dtfixed16.;
run;

 

 

is one way. Note that the number of displayed characters, as with other formats can be set by specifying the width in the format statement. You chose whether to display the seconds or not, but the value is there.

 

 

If you really must use that stupid Micro$lop date time appearance. And comparisons do not use formatted values.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 4 replies
  • 1518 views
  • 0 likes
  • 3 in conversation