09-26-2016 10:47 PM
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 :
Proc export data=work.test
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.
Uma Shanker Saini
09-27-2016 01:57 AM
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.
09-27-2016 02:19 AM
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.***;
09-27-2016 04:57 AM
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.