🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-09-2019 03:39 AM
(10737 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
7 REPLIES 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about
data test;
datetime='20may2019 09:11:54'dt;
format datetime datetime14.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! If datetime is character variable, then how will you deal with
it? Just apply input function?
it? Just apply input function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! it works for me 😛