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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.