Hi Al,
I am able to get the datatime in the ddmmyyhhmmss format but 0 is missing at start
output :-3102023100202
but looking for :- 03102023100202
%let now=%sysfunc(datetime());
%let date_time = %sysfunc(inputn(%sysfunc(putn(%sysfunc(datepart(&now)),DDMMYYN8.)),8.))%sysfunc(timepart(&now),B8601TM6);
%put &date_time.;
Thanks,
SS
%let date_time=%sysfunc(putn(%sysfunc(datepart(&now)),ddmmyyn8.))%sysfunc(timepart(&now),B8601TM6);
No need for PUTN in the above creation of macro variable &DATE_TIME
You put the result in a numerical variable, and the default behavior implicit leading zeroes are not displayed.
Maybe it would be better keep your value as a SAS datetime value, and have custom format to display it according to your requirements?
https://documentation.sas.com/doc/en/pgmsascdc/v_043/proc/p0n990vq8gxca6n1vnsracr6jp2c.htm
%let date_time=%sysfunc(putn(%sysfunc(datepart(&now)),ddmmyyn8.))%sysfunc(timepart(&now),B8601TM6);
No need for PUTN in the above creation of macro variable &DATE_TIME
For any technical use, I strongly (and I mean STRONGLY) advise against using a DMY date. Use YMD instead.
So I suggest
%let date_time = %sysfunc(compress(%sysfunc(datetime(),b8601dt15.),T));
proc format;
picture ddmmyyhhmmss
low-high = '%0d%0m%Y%0H%0M%0S' (datatype=datetime);
run;
%let now = %sysfunc(datetime(),ddmmyyhhmmss.);
%put &now;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.