SAS - Custom Date Format - YYYYMMDDhhmmss

Maiia S. picture Maiia S. · Jun 8, 2017 · Viewed 8.5k times · Source

I need to add a current date to the output I am exporting from SAS in the following format: filename_YYYYMMDDhhmmss.csv

I am creating a macro variable the following way:

%let date_human = %sysfunc(today(), YYYYMMDDn8.);

Does anybody know how to create a custom format for the date I have got? datetime20. gives an incorrect one.

Thank you.

Answer

Tom picture Tom · Jun 8, 2017

Use the B8601 formats.

%let now=%sysfunc(datetime());
%let date_human=%sysfunc(putn(&now,B8601DN8))%sysfunc(timepart(&now),B8601TM6);