BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Babloo
Rhodochrosite | Level 12

Is there a way that we can convert the datetime value 20MAY19:09:11:54 to like this 20.05.2019 09:11?

 

I'm not finding any SAS datetime format which format like 20.05.2019 09:11.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Sorry, I mistyped, the format should be defined as

 

proc format; 
  picture dtfmt (default=16)
    low - high = '%0d.%0m.%Y %0H:%0M' (datatype=datetime)
  ;
run;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

How about

 

data test;
  datetime='20may2019 09:11:54'dt;
  format datetime datetime14.;
run;
PeterClemmensen
Tourmaline | Level 20

Alternatively, you could just roll out your own format

 

proc format; 
  picture dtfmt (default=16)
    low - high = '0%d.0%m.%Y 0%H:0%M' (datatype=datetime)
  ;
run;

data test;
  datetime='20may2019 09:11:54'dt;
  format datetime dtfmt.;
run;
Babloo
Rhodochrosite | Level 12
Thank you! If datetime is character variable, then how will you deal with
it? Just apply input function?
PeterClemmensen
Tourmaline | Level 20

Use the Input Function and the Anydtdtm18. Informat like this

 

proc format; 
  picture dtfmt (default=16)
    low - high = '0%d.0%m.%Y 0%H:0%M' (datatype=datetime)
  ;
run;

data test;
  datetime='20may2019 09:11:54';
  numdt=input(datetime, anydtdtm18.);
  format numdt dtfmt.;
run;
Babloo
Rhodochrosite | Level 12

Format which you provided is OK to some extend but I'm not seeing the right value in hh:mm. Value which I got in the Output is 09.09.2019 010:0 instead of 09.09.2019 10:50.

 

Please see the log below

 

1889       proc format;
1890         picture dtfmt (default=16)
1891           low - high = '0%d.0%m.%Y 0%H:0%M' (datatype=datetime)
1892         ;
NOTE: Format DTFMT is already on the library WORK.FORMATS.
NOTE: Format DTFMT has been output.
1893       run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

1894       data metadata;
1895       %let etls_stepStartTime = %sysfunc(datetime(), datetime17.);
1896       %put %str(NOTE: &etls_stepStartTime.);
NOTE: 09SEP19:10:50:17
1897      SCHDLD_OBJ_RUN_STRT_TMST=%sysfunc(inputn("&etls_stepStartTime",datetime17.));
1898       format SCHDLD_OBJ_RUN_STRT_TMST dtfmt.;;
1899       run;
PeterClemmensen
Tourmaline | Level 20

Sorry, I mistyped, the format should be defined as

 

proc format; 
  picture dtfmt (default=16)
    low - high = '%0d.%0m.%Y %0H:%0M' (datatype=datetime)
  ;
run;
Dulcinea
Calcite | Level 5

Thank you! it works for me 😛

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 9478 views
  • 3 likes
  • 3 in conversation