BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sathya66
Barite | Level 11

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
%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

--
Paige Miller

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

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

 

 

Data never sleeps
PaigeMiller
Diamond | Level 26
%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

--
Paige Miller
Kurt_Bremser
Super User

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));
LinusH
Tourmaline | Level 20
proc format;
	picture ddmmyyhhmmss
		low-high = '%0d%0m%Y%0H%0M%0S' (datatype=datetime);
run;

%let now = %sysfunc(datetime(),ddmmyyhhmmss.);
%put &now;
Data never sleeps

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1313 views
  • 1 like
  • 4 in conversation