BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DME790
Pyrite | Level 9

Hi,

 

I'm trying to add the date and time to the end of an excel file name, with no colons, within a LIBNAME.

 

I currently have 

 

Data Null;

call SYMPUTX('Date',put(totday(),Date9.));

Call SYMPUTX('Hour',Hour(datetime()));

Call SYMPUTX('Minute',Minute(datetime()));

 

Run;

 

LIBNAME XL XLSX "/SASData/Dean/Export1_&Date-&Hour&Minute..xlsx";

 

This returns as

 

 LIBNAME XL XLSX "/SASData/Dean/Export1_11Jan2017-939..xls";

 

 

The 9 being the hour the 39 being the minutes. However if the minutes is a single number it only returns one digit.

 

eg if the time was 9:09 the output would be 99.

 

I want to get the hour and minute to display two digits each. - so in the above example the out put would be 0909.

 

I don't mind if the output is in 24hr clock

 

 

This is what I would like the output to be.

LIBNAME XL XLSX "/SASData/Dean/Export1_11Jan2017-0939..xlsx";

 

Any help[ appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Format it with Z2 similar to how you formatted the date to DATE9.

 

Or roll your own date time format that does both date and time in one shot. If you use this across multiple projects it's not a bad thing to have around.

 

 

proc format;
picture file_date (default=20)  low-high = '%0d%3B%000y_%0H%0M' (datatype=datetime);
run;

Data Null;
call SYMPUTX('Date',put(today(),Date9.));
Call SYMPUTX('Hour',put(Hour(datetime()), z2.));
Call SYMPUTX('Minute',put(Minute(datetime()), z2.));

Call SYMPUTX('file_date',put(datetime(), file_Date.));

Run;

%put &file_date;
  

View solution in original post

4 REPLIES 4
Reeza
Super User

Format it with Z2 similar to how you formatted the date to DATE9.

 

Or roll your own date time format that does both date and time in one shot. If you use this across multiple projects it's not a bad thing to have around.

 

 

proc format;
picture file_date (default=20)  low-high = '%0d%3B%000y_%0H%0M' (datatype=datetime);
run;

Data Null;
call SYMPUTX('Date',put(today(),Date9.));
Call SYMPUTX('Hour',put(Hour(datetime()), z2.));
Call SYMPUTX('Minute',put(Minute(datetime()), z2.));

Call SYMPUTX('file_date',put(datetime(), file_Date.));

Run;

%put &file_date;
  
DME790
Pyrite | Level 9

Thanks Reza. - helpful as always - works a treat.

 

Cheers

Patrick
Opal | Level 21

One way to go:

Data Null;
  call SYMPUTX('Date',put(today(),Date9.));
  Call SYMPUTX('Hour',put(Hour(datetime()),z2.));
  Call SYMPUTX('Minute',put(Minute(datetime()),z2.));
Run;
DME790
Pyrite | Level 9

Thanks Patrick - yours and Reeza's advice works a treat

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2023 views
  • 1 like
  • 3 in conversation