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.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.