BookmarkSubscribeRSS Feed
VicBrookes
Fluorite | Level 6

Within SAS Enterprise Guide i've set up a automated process to export an excel file to a file.

At the moment it replaces it's self every time the query runs. However i don't wish it to do this, i would like it if it was a new file every time and was named to show the date and time the file exported for auditing reasons.

an example of what i would like is...

File13112016_1000

File13112016_1300

File13112016_1500

File13112016_1700

 

Thank you in advance for any help you could provide. I love SAS as it really helps my role but i don't use it enough to understand it as well as i know you guys do.

 

All the best

 

Vic

2 REPLIES 2
Reeza
Super User

How are you controlling the name of the output file?

 

You can create two macro variables that hold the date and time in the respective formats and then use them in the name. 

 

file_name = "name&date._&time";

 

%let cdate=%sysfunc(today(), ddmmyyn8.);
%put &cdate.;

*this isnt correct format, you need to find the one that doesnt have colons;
%let ctime=%sysfunc(time(), time4.));
%put &ctime.;

 

 

Kurt_Bremser
Super User

My favorite for creating control variables is to do it in a data step and use call symput:

data _null_;
call symput('cdate',put(date(),ddmmyyn8.));
timestr = put(time(),tod5.);
call symput('ctime',substr(timestr,1,2)!!substr(timestr,4,2));
run;
%put &cdate.;
%put &ctime.;

Note that the tod. format outputs a leading zero for single-digit hours (what the time. format does not do).

In a data step I can hack away using simple data step syntax without having to repeatedly use %sysfunc or %eval.

sas-innovate-2024.png

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.

 

Register now!

Discussion stats
  • 2 replies
  • 952 views
  • 0 likes
  • 3 in conversation