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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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