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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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