- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I need your kind help to get system date in YYYYMMDDHHMMSS format.
data _null_;
export_date=put(datetime(), datetime20.);
put export_date;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want an exact match, you can roll out your own format like this
proc format;
picture dtfmt (default=30)
other = '%Y%0m%0d%0H%0M%0S' (datatype=datetime)
;
run;
data _null_;
export_date=put(datetime(), dtfmt.);
put export_date;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is this close enough:
data _null_;
export_date=put(datetime(), E8601DT.);
put export_date;
run;
See Dictionary of Formats for a list of formats
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about
data _null_;
export_date=put(datetime(), B8601DT.);
put export_date;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@DeepakSwain wrote:
Date will look like 20211012134021
Requires custom format:
proc format; picture mydatetime low-high='%Y%0m%0d%0H%0M%0S' (datatype=datetime) ; run; data example; x='12Oct2021:13:40:21'dt; put x= mydatetime.; run;
The directives in the Picture statement are case sensitive, the m is month, M is minutes mix them up and don't expect to understand any result. Also this is one place that you really need to use single quotes around the directives for the format, otherwise the directives get interpreted as macro calls and will throw errors. It will be up to you to make sure that the format is available in any session than needs to use this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@ballardw Great minds think alike 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't think there is a format that is exactly YYYYMMDDHHMMSS, this comes close:
data null;
export_date=datetime();
format export_date b8601dt20.0;
run;
If that isn't close enough, the PICTURE statement in PROC FORMAT allows you to create your own custom date/time formats that will match exactly.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I want 20211021134607.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want an exact match, you can roll out your own format like this
proc format;
picture dtfmt (default=30)
other = '%Y%0m%0d%0H%0M%0S' (datatype=datetime)
;
run;
data _null_;
export_date=put(datetime(), dtfmt.);
put export_date;
run;