<?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 Adding sequence numbers to filenames.. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533466#M146260</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I need help in generating sequential numbers to filename.&lt;/P&gt;&lt;P&gt;Example filename fileref&amp;nbsp; "path#.ext";&amp;nbsp;&lt;/P&gt;&lt;P&gt;(where # will be the file sequence number)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I obtain this?&amp;nbsp; Any help will be greatly appreciated. Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 07 Feb 2019 02:30:21 GMT</pubDate>
    <dc:creator>Aidaan_10</dc:creator>
    <dc:date>2019-02-07T02:30:21Z</dc:date>
    <item>
      <title>Adding sequence numbers to filenames..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533466#M146260</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I need help in generating sequential numbers to filename.&lt;/P&gt;&lt;P&gt;Example filename fileref&amp;nbsp; "path#.ext";&amp;nbsp;&lt;/P&gt;&lt;P&gt;(where # will be the file sequence number)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I obtain this?&amp;nbsp; Any help will be greatly appreciated. Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 02:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533466#M146260</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2019-02-07T02:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Adding sequence numbers to filenames..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533468#M146261</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174192"&gt;@Aidaan_10&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I need help in generating sequential numbers to filename.&lt;/P&gt;&lt;P&gt;Example filename fileref&amp;nbsp; "path#.ext";&amp;nbsp;&lt;/P&gt;&lt;P&gt;(where # will be the file sequence number)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I obtain this?&amp;nbsp; Any help will be greatly appreciated. Thanks&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you supply more context?&amp;nbsp; Otherwise this works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename fileref "path1.txt";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let num=1;&lt;/P&gt;&lt;P&gt;filename fileref "path&amp;amp;num..txt";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will temporary files help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename fileref temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then reference the file via the fileref only.&amp;nbsp; See the doc for details.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 02:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533468#M146261</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-02-07T02:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding sequence numbers to filenames..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533471#M146263</link>
      <description>Hi Scott,&lt;BR /&gt;Thanks for the reply but these are not temporary files. We load the data file every now and then with same names so I need to add a sequence number to them.</description>
      <pubDate>Thu, 07 Feb 2019 02:50:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533471#M146263</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2019-02-07T02:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Adding sequence numbers to filenames..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533480#M146267</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Edit&lt;/STRONG&gt;:&amp;nbsp; What I mean by context is:&lt;/P&gt;&lt;P&gt;* Are you looping in a macro?&lt;/P&gt;&lt;P&gt;* Do you need to create multiple files from a single data step?&lt;/P&gt;&lt;P&gt;* Can you supply the relevant code excerpts?&lt;/P&gt;&lt;P&gt;* Etc...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You still haven't added context, so this will be my last guess:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* get path to work directory ;
%let work=%sysfunc(pathname(work));

* create some dummy files ;
data _null_;
   length file $200;
   do i=1 to 5;
      file=cats("&amp;amp;work","\foo",i,".txt");
      file foo filevar=file;
      put 'x';
   end;
run;

* get list of files ;
%dirlist(dir=&amp;amp;work, filter=basename=:'foo' and ext='txt')
%let num=%nobs(dirlist);

* create more files ;
data _null_;
   length file $200;
   retain num &amp;amp;num;
   do i=1 to 5;
      num+1;
      file=cats("&amp;amp;work","\foo",num,".txt");
      file foo filevar=file;
      put 'x';
   end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/dirlist.sas" target="_blank" rel="noopener"&gt;https://github.com/scottbass/SAS/blob/master/Macro/dirlist.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/nobs.sas" target="_blank" rel="noopener"&gt;https://github.com/scottbass/SAS/blob/master/Macro/nobs.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Adjust to suit.&amp;nbsp; For example, you might need to parse dirlist --&amp;gt; filename to get max suffix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another approach is to just start a counter=1, use the fileexist function to check for existence of foo&amp;lt;counter&amp;gt;.txt, and increment counter until file does not exist.&amp;nbsp; This should perform ok unless you had thousands of foo&amp;lt;counter&amp;gt;.txt files in your output directory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 03:39:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533480#M146267</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-02-07T03:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Adding sequence numbers to filenames..</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533529#M146289</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174192"&gt;@Aidaan_10&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Scott,&lt;BR /&gt;Thanks for the reply but these are not temporary files. We load the data file every now and then with same names so I need to add a sequence number to them.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you talking about dataset-names or filenames?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are talking about dataset-names, have a look at &lt;A class="ng-scope" tabindex="0" title="" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lrcon&amp;amp;docsetTarget=p0apy93gsj2bzmn1awyqfe7kklkp.htm&amp;amp;locale=de" data-docset-id="lrcon" data-docset-version="9.4" data-original-href="p0apy93gsj2bzmn1awyqfe7kklkp.htm"&gt;Understanding Generation Data Sets&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 07:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-sequence-numbers-to-filenames/m-p/533529#M146289</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-07T07:41:14Z</dc:date>
    </item>
  </channel>
</rss>

