<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic how can i dynamically change flat file name using sas? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-dynamically-change-flat-file-name-using-sas/m-p/512903#M2467</link>
    <description>&lt;P&gt;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?&amp;nbsp; I tried using below snippet but its not working beyond r01 version.&lt;/P&gt;&lt;P&gt;options mprint mtrace mlogic macrogen symbolgen notes source source2;&lt;/P&gt;&lt;P&gt;%MACRO FILNAMES;&lt;BR /&gt;&amp;nbsp; %LET _ASOFDT1 = 20181019;&lt;BR /&gt;&amp;nbsp; %LET VER = 0;&lt;BR /&gt;&amp;nbsp; FILENAME _dtltrad "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %IF &amp;amp;sysfilrc &amp;gt; 0 %then %DO;&lt;BR /&gt;&amp;nbsp; %LET VER = %EVAL(&amp;amp;VER +1);&lt;BR /&gt;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; = "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %END;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %ELSE %DO;&lt;BR /&gt;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; = "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %END;&lt;BR /&gt;&amp;nbsp; %PUT &amp;amp;_DTLTRAD;&lt;BR /&gt;&amp;nbsp; %PUT &amp;amp;VER.;&lt;BR /&gt;&amp;nbsp; FILENAME _dtltrad &amp;amp;_DTLTRAD;&lt;BR /&gt;%MEND FILNAMES;&lt;/P&gt;&lt;P&gt;%FILNAMES;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Wed, 14 Nov 2018 11:10:50 GMT</pubDate>
    <dc:creator>khushi</dc:creator>
    <dc:date>2018-11-14T11:10:50Z</dc:date>
    <item>
      <title>how can i dynamically change flat file name using sas?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-dynamically-change-flat-file-name-using-sas/m-p/512903#M2467</link>
      <description>&lt;P&gt;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?&amp;nbsp; I tried using below snippet but its not working beyond r01 version.&lt;/P&gt;&lt;P&gt;options mprint mtrace mlogic macrogen symbolgen notes source source2;&lt;/P&gt;&lt;P&gt;%MACRO FILNAMES;&lt;BR /&gt;&amp;nbsp; %LET _ASOFDT1 = 20181019;&lt;BR /&gt;&amp;nbsp; %LET VER = 0;&lt;BR /&gt;&amp;nbsp; FILENAME _dtltrad "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %IF &amp;amp;sysfilrc &amp;gt; 0 %then %DO;&lt;BR /&gt;&amp;nbsp; %LET VER = %EVAL(&amp;amp;VER +1);&lt;BR /&gt;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; = "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %END;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %ELSE %DO;&lt;BR /&gt;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; = "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %END;&lt;BR /&gt;&amp;nbsp; %PUT &amp;amp;_DTLTRAD;&lt;BR /&gt;&amp;nbsp; %PUT &amp;amp;VER.;&lt;BR /&gt;&amp;nbsp; FILENAME _dtltrad &amp;amp;_DTLTRAD;&lt;BR /&gt;%MEND FILNAMES;&lt;/P&gt;&lt;P&gt;%FILNAMES;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 11:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-dynamically-change-flat-file-name-using-sas/m-p/512903#M2467</guid>
      <dc:creator>khushi</dc:creator>
      <dc:date>2018-11-14T11:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: how can i dynamically change flat file name using sas?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-dynamically-change-flat-file-name-using-sas/m-p/512912#M2468</link>
      <description>&lt;P&gt;As with your other post in terms of code formatting.&amp;nbsp; With regards to this, why do you want to increment filename?&amp;nbsp; Would not a version control system or something specifically designed for the task not be better?&amp;nbsp; Just thinking your going to have to code various checks to ensure this works ok, is it worth it.&amp;nbsp; For instance, what if a file gets removed, or needs replacing etc.&amp;nbsp; This isn't to say it can't be done with something like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  do i=1 to 100;  /* Set 100 to something big */
    if fileexist(cats("capp_1q18_acas_detail_r0",put(i,best.),"_primary.txt"))=0 then do;
      call symputx('next',i);
      leave;
    end;
  end;
run;

%put Next available number is: &amp;amp;next.;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Nov 2018 11:44:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-dynamically-change-flat-file-name-using-sas/m-p/512912#M2468</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-14T11:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: how can i dynamically change flat file name using sas?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-can-i-dynamically-change-flat-file-name-using-sas/m-p/512989#M2477</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/246403"&gt;@khushi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;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?&amp;nbsp; I tried using below snippet but its not working beyond r01 version.&lt;/P&gt;
&lt;P&gt;options mprint mtrace mlogic macrogen symbolgen notes source source2;&lt;/P&gt;
&lt;P&gt;%MACRO FILNAMES;&lt;BR /&gt;&amp;nbsp; %LET _ASOFDT1 = 20181019;&lt;BR /&gt;&amp;nbsp; %LET VER = 0;&lt;BR /&gt;&amp;nbsp; FILENAME _dtltrad "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %IF &amp;amp;sysfilrc &amp;gt; 0 %then %DO;&lt;BR /&gt;&amp;nbsp; %LET VER = %EVAL(&amp;amp;VER +1);&lt;BR /&gt;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; = "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %END;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; %ELSE %DO;&lt;BR /&gt;&amp;nbsp; %LET _DTLTRAD&amp;nbsp; = "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;&lt;BR /&gt;&amp;nbsp; %END;&lt;BR /&gt;&amp;nbsp; %PUT &amp;amp;_DTLTRAD;&lt;BR /&gt;&amp;nbsp; %PUT &amp;amp;VER.;&lt;BR /&gt;&amp;nbsp; FILENAME _dtltrad &amp;amp;_DTLTRAD;&lt;BR /&gt;%MEND FILNAMES;&lt;/P&gt;
&lt;P&gt;%FILNAMES;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please make sure that your question text aligns somewhat with any example code.&lt;/P&gt;
&lt;P&gt;You say that you want to basically use a file name similar to "qa_test_r01"&lt;BR /&gt;&amp;nbsp;but you code is going to generate names like "CAPP_1Q18_ACAS_Detail_R0120181019_Primary".&lt;/P&gt;
&lt;P&gt;When question and code do not come close then we spend a lot of time &lt;STRONG&gt;guessing&lt;/STRONG&gt; which is actually meant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you actually make multiple files on the same date (&lt;STRONG&gt;assumes&lt;/STRONG&gt; use of _ASOFDT1&amp;nbsp;as a date, not mentioned or defined in question text).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why only -ro1: you only tell it to do one iteration. There is no&amp;nbsp;repeat loop in your code.&amp;nbsp;I suspect you may have been thinking you were doing either a DO UNTIL or DO WHILE such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%IF &amp;amp;sysfilrc &amp;gt; 0 %then %DO %until &amp;amp;sysfilrc=0;
  %LET VER = %EVAL(&amp;amp;VER +1);
  %LET _DTLTRAD  = "CAPP_1Q18_ACAS_Detail_R0&amp;amp;VER._&amp;amp;_ASOFDT1._Primary" ;
  FILENAME _dtltrad &amp;amp;_DTLTRAD;
%END;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;without&lt;/STRONG&gt; the %else %do block.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 16:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-can-i-dynamically-change-flat-file-name-using-sas/m-p/512989#M2477</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-14T16:09:27Z</dc:date>
    </item>
  </channel>
</rss>

