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;
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;
Is this close enough:
data _null_;
export_date=put(datetime(), E8601DT.);
put export_date;
run;
See Dictionary of Formats for a list of formats
How about
data _null_;
export_date=put(datetime(), B8601DT.);
put export_date;
run;
@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.
@ballardw Great minds think alike 😉
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.
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;
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!
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.