SAS Office Analytics, SAS Add-In for Microsoft Office, and other integrations

Naming an output file with date and time

Reply
Occasional Contributor
Posts: 7

Naming an output file with date and time

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

Super User
Posts: 18,995

Re: Naming an output file with date and time

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.;

 

 

Super User
Posts: 7,371

Re: Naming an output file with date and time

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 2 replies
  • 200 views
  • 0 likes
  • 3 in conversation