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
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;
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;
Thanks Reza. - helpful as always - works a treat.
Cheers
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;
Thanks Patrick - yours and Reeza's advice works a treat
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.