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.

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