Hi Team,
I need to generate outfile from proc eport with running serial number if file already exist with same date.
sample code to generate file name with date :
%Let fname=%sysfunc(today(),mmddyyn8.);
%let file=uma;
Proc export data=work.test
outfile="C:\Desktop\&file&fname.01.txt"
dbms=csv;
quit;
Code would generate file : uma0927201601.txt
I am looking for that "01" in filename should get change to 02 and 03....if i generate the same file today itself.
Regards,
Uma Shanker Saini
This document describes how to obtain a directory listing using only SAS functions. You can then subset on the first part of your filename, and then iterate to the last found file, add 1, and create a new filename.
Filename Txt_List Pipe 'dir "C:\ ... \*.txt" /b';
Data _NULL_;
Infile Txt_List TruncOver;
Input Filename $100.;
* If Find(Filename,<Currentdatestring>);
Counter=Input(Substr(Filename,Find(Filename,'.')-2,2),2.)+1;
Call SymputX('Counter',Counter);
Run;
%Put **&Counter.***;
Am not sure that is the best approach. If you absolutely have to create separate files (and that would be my first pushback), and they abosultely have to have data in the filename (again, another pushback), then why not use a full date/timestamp and forget about incrementals? You can simply export your data as:
proc export data=work.test outfile="c:\desktop\uma%sysfunc(date()date.)_%sysfunc(time(),tod8.).csv" dbms=csv; quit;
Note, its a good idea to have the file extension show what the file contains, txt = text, csv= csv.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.