@khushi wrote:
My file name is qa_test_r00. It is flat file. I want to change it to qa_test_r01 if qa_test_r00 already exists.Then to qa_test_r02 next time once file r01 is created. Can you help me with it? I tried using below snippet but its not working beyond r01 version.
options mprint mtrace mlogic macrogen symbolgen notes source source2;
%MACRO FILNAMES;
%LET _ASOFDT1 = 20181019;
%LET VER = 0;
FILENAME _dtltrad "CAPP_1Q18_ACAS_Detail_R0&VER._&_ASOFDT1._Primary" ;
%IF &sysfilrc > 0 %then %DO;
%LET VER = %EVAL(&VER +1);
%LET _DTLTRAD = "CAPP_1Q18_ACAS_Detail_R0&VER._&_ASOFDT1._Primary" ;
%END;
%ELSE %DO;
%LET _DTLTRAD = "CAPP_1Q18_ACAS_Detail_R0&VER._&_ASOFDT1._Primary" ;
%END;
%PUT &_DTLTRAD;
%PUT &VER.;
FILENAME _dtltrad &_DTLTRAD;
%MEND FILNAMES;
%FILNAMES;
Thanks in advance
Please make sure that your question text aligns somewhat with any example code.
You say that you want to basically use a file name similar to "qa_test_r01"
but you code is going to generate names like "CAPP_1Q18_ACAS_Detail_R0120181019_Primary".
When question and code do not come close then we spend a lot of time guessing which is actually meant.
Do you actually make multiple files on the same date (assumes use of _ASOFDT1 as a date, not mentioned or defined in question text).
Note that if you have this run more than 9 times you are going to have _r010 names, which will seriously mess with any sort order of names.
Why only -ro1: you only tell it to do one iteration. There is no repeat loop in your code. I suspect you may have been thinking you were doing either a DO UNTIL or DO WHILE such as
%IF &sysfilrc > 0 %then %DO %until &sysfilrc=0;
%LET VER = %EVAL(&VER +1);
%LET _DTLTRAD = "CAPP_1Q18_ACAS_Detail_R0&VER._&_ASOFDT1._Primary" ;
FILENAME _dtltrad &_DTLTRAD;
%END;
without the %else %do block.