Re: creating a filename with concatenated date & time values

  • Follow


hi ... Andrew Karp offered another solution to this problem ...

*********************
Let me offer another suggestion/approach, please.

If the goal is to put the date/time of file creation in the name of the
output data set (or file name, if you are exporting a SAS data set "out"
to an XLS or CSV file,) we need a file name that starts with a letter or
an underscore.   My approach would be to determine the date and time (to the nearest
second) before writing out the file, and from these values create a
macro symbol table variable with those values, plus some text and
underscores, that can be used as either the file name in a PROC EXPORT
or a DATA STEP.  <more>

data _null_;
call symputx('created',(cats('DATE_',translate((put(today(),yymmdd10.)),'_','-'),
           '_','TIME_',translate((put(time(),time5.)),'_',':'))));
run;
**********************

I'd like to concur in that it solves a problem that might occur with previous
posted answers ... multiple execution of the two statements ...

file_name=translate(catt(put(today(),yymmdd10.),'__',put(time(),time.),'.txt'),'__','-:');
file x filevar=file_name;

can produce multiple files if processing a large data set (or a large file of text data with an
input statement).


* a large file;
data xyz;
do j=1 to 1E6;
   output;
end;
run;

*
not the way to do this
produces multiple files
since time changes during data step
and the FILE statement executes multiple times
;

data _null_;
file_name=translate(catt(put(today(),yymmdd10.),'__',put(time(),time.),'.txt'),'__','-:');
file x filevar=file_name;
set xyz;
put "this may not work with a large file";
run;

*
produces one file
FILE statement executes once
;

data _null_;
file_name=translate(catt(put(today(),yymmdd10.),'__',put(time(),time.),'.txt'),'__','-:');
file x filevar=file_name;

do until (done);
   set xyz end = done;
   put "this works";
end;

stop;
run;

* or, Andrew's suggestion ... produces one file;

data _null_;
call symputx('created',(cats(translate((put(today(),yymmdd10.)),'_','-'),
           '__',translate((put(time(),time.)),'_',':'))));
run;

data _null_;
file "&created..txt";
set xyz;
put "this works";
run;

--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
0
Reply msz03 (782) 2/27/2010 9:19:40 PM


0 Replies
213 Views

(page loaded in 0.027 seconds)

Similiar Articles:













7/27/2012 5:48:22 PM


Reply: