<?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 Re: Writing a do loop macro to find a string and increment in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435108#M282000</link>
    <description>Replace your string with the macro variable so you're not replacing strings, the macro variable has changed and the code will loop through with that new number.</description>
    <pubDate>Wed, 07 Feb 2018 23:05:06 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-02-07T23:05:06Z</dc:date>
    <item>
      <title>Writing a do loop macro to find a string and increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435104#M281998</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can a global macro be created that will read in a file, increment the suffix of file name by 1 then read in the updated file name, and repeat this for a set number of files?&lt;/P&gt;&lt;P&gt;For example, I have 100 files that are named 'scores001' 'scores002' 'scores003'...'scores100' that need to be read into SAS then saved to a permanent 'scorestotal' file. These files have .dat extensions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried to use a %macro do loop but the problem is the file names are written in several places throughout my code. I would need a macro that finds the name 'scores' then appends numbers dynamically and saves the output to a permanent file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The three lines of the code that need to be updated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename class &amp;amp;scores1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data scores1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if _n_=1 then set param; set scores1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS 9.4 X64_8PRO platform on a Windows version 6.2.9200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your time!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 22:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435104#M281998</guid>
      <dc:creator>tjc87</dc:creator>
      <dc:date>2018-02-07T22:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a do loop macro to find a string and increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435107#M281999</link>
      <description>&lt;P&gt;Don't. Import all in one step instead. Unless they're really big files. In that case a macro loop is quite easy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop_nums(start=, end=);

    %do i=&amp;amp;start %to &amp;amp;end;

        %let index_counter = %sysfunc(putn(&amp;amp;i, z3.)); 

        %put &amp;amp;index_counter;

    %end;


%mend;

%loop_nums(start=10, end=105);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: Instructions on how to import all at once:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-text-files-that-have/ta-p/223627&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're having difficulty post your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/190793"&gt;@tjc87&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can a global macro be created that will read in a file, increment the suffix of file name by 1 then read in the updated file name, and repeat this for a set number of files?&lt;/P&gt;
&lt;P&gt;For example, I have 100 files that are named 'scores001' 'scores002' 'scores003'...'scores100' that need to be read into SAS then saved to a permanent 'scorestotal' file. These files have .dat extensions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried to use a %macro do loop but the problem is the file names are written in several places throughout my code. I would need a macro that finds the name 'scores' then appends numbers dynamically and saves the output to a permanent file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The three lines of the code that need to be updated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filename class &amp;amp;scores1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data scores1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if _n_=1 then set param; set scores1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using SAS 9.4 X64_8PRO platform on a Windows version 6.2.9200&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your time!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 23:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435107#M281999</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-07T23:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a do loop macro to find a string and increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435108#M282000</link>
      <description>Replace your string with the macro variable so you're not replacing strings, the macro variable has changed and the code will loop through with that new number.</description>
      <pubDate>Wed, 07 Feb 2018 23:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435108#M282000</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-07T23:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a do loop macro to find a string and increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435130#M282001</link>
      <description>&lt;P&gt;The DAT file extension has no standard meaning so that really doesn't help. Many people and/or programs use it for "data" and are stuck back when DOS limited the extensions to 3 characters. But the content could be text, fixed column, delimited, named, or a&amp;nbsp;proprietary binary format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the "meanings" for DAT extensions was also "Digital Audio Tape" which was a high definition sound format. I doubt that is what you have though.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 00:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435130#M282001</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-08T00:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a do loop macro to find a string and increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435429#M282002</link>
      <description>&lt;P&gt;The .dat files are text files with 3 rows of numeric values.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 20:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435429#M282002</guid>
      <dc:creator>tjc87</dc:creator>
      <dc:date>2018-02-08T20:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a do loop macro to find a string and increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435433#M282003</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/190793"&gt;@tjc87&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The .dat files are text files with 3 rows of numeric values.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you should really use the approach I linked to that will import all at once and identify the source. Its the most efficient method. And no macros.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 20:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435433#M282003</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-08T20:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a do loop macro to find a string and increment</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435456#M282004</link>
      <description>&lt;P&gt;The 'wildcard import all files in a folder' solution worked! I appreciate your help!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 21:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-do-loop-macro-to-find-a-string-and-increment/m-p/435456#M282004</guid>
      <dc:creator>tjc87</dc:creator>
      <dc:date>2018-02-08T21:34:47Z</dc:date>
    </item>
  </channel>
</rss>

