<?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 Using macro with text files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449025#M283544</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I have the files 123.txt, 456.txt and 789.txt and a program like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*******************************************************&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%let n= 123.txt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;*******************************************************&lt;/P&gt;&lt;P&gt;And I need to replace with 456.txt and 789.txt, and run again.&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 trying this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*****************************************************&lt;/P&gt;&lt;P&gt;%macro mb(stg);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%let n= &amp;amp;stg..txt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let gball="123 456 789";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do %while (&amp;amp;k&amp;lt;=3);&lt;/P&gt;&lt;P&gt;%let gb=scan(&amp;amp;gball,&amp;amp;k);&lt;/P&gt;&lt;P&gt;%mb(&amp;amp;gb);&lt;/P&gt;&lt;P&gt;%let k=k+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;*****************************************************&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can note that I'm not very expert with macro, so any comment is very usefull.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for yours answers!!&lt;/SPAN&gt;&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;</description>
    <pubDate>Tue, 27 Mar 2018 15:42:01 GMT</pubDate>
    <dc:creator>mbas</dc:creator>
    <dc:date>2018-03-27T15:42:01Z</dc:date>
    <item>
      <title>Using macro with text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449025#M283544</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I have the files 123.txt, 456.txt and 789.txt and a program like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*******************************************************&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%let n= 123.txt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;*******************************************************&lt;/P&gt;&lt;P&gt;And I need to replace with 456.txt and 789.txt, and run again.&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 trying this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*****************************************************&lt;/P&gt;&lt;P&gt;%macro mb(stg);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%let n= &amp;amp;stg..txt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let gball="123 456 789";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do %while (&amp;amp;k&amp;lt;=3);&lt;/P&gt;&lt;P&gt;%let gb=scan(&amp;amp;gball,&amp;amp;k);&lt;/P&gt;&lt;P&gt;%mb(&amp;amp;gb);&lt;/P&gt;&lt;P&gt;%let k=k+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;*****************************************************&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can note that I'm not very expert with macro, so any comment is very usefull.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for yours answers!!&lt;/SPAN&gt;&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;</description>
      <pubDate>Tue, 27 Mar 2018 15:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449025#M283544</guid>
      <dc:creator>mbas</dc:creator>
      <dc:date>2018-03-27T15:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro with text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449030#M283545</link>
      <description>&lt;P&gt;Your %do loop cannot be in open code, it can only work inside a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You haven't stated exactly what the problem is with this code, so ... what is the problem?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 15:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449030#M283545</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-27T15:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro with text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449034#M283546</link>
      <description>&lt;P&gt;What exactly is your question? It's not clear what you need help with here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example 1, 3, 4 may be helpful to you here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're importing multiple text files that are all the same, see this post as well:&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;Last but not least, look at CALL EXECUTE for a simple way to call a macro multiple times.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I usually use a pipe to get the list of files into a data set, then use CALL EXECUTE to call the macro once for each file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/201416"&gt;@mbas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I have the files 123.txt, 456.txt and 789.txt and a program like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*******************************************************&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;%let n= 123.txt;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;*******************************************************&lt;/P&gt;
&lt;P&gt;And I need to replace with 456.txt and 789.txt, and run again.&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 trying this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*****************************************************&lt;/P&gt;
&lt;P&gt;%macro mb(stg);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;%let n= &amp;amp;stg..txt;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let gball="123 456 789";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do %while (&amp;amp;k&amp;lt;=3);&lt;/P&gt;
&lt;P&gt;%let gb=scan(&amp;amp;gball,&amp;amp;k);&lt;/P&gt;
&lt;P&gt;%mb(&amp;amp;gb);&lt;/P&gt;
&lt;P&gt;%let k=k+1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;*****************************************************&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can note that I'm not very expert with macro, so any comment is very usefull.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks for yours answers!!&lt;/SPAN&gt;&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 15:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449034#M283546</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-27T15:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro with text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449035#M283547</link>
      <description>And assuming you are trying to write a macro, first get your base case working, that is, what does the code look like for a single file. Once you have that working it's relatively trivial to convert it to a macro.</description>
      <pubDate>Tue, 27 Mar 2018 15:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449035#M283547</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-27T15:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro with text files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449045#M283548</link>
      <description>&lt;P&gt;Besides needing a macro to use %DO, you also need to get rid of the quotes, and you need to use the macro function (%scan) instead of the DATA step function (scan).&amp;nbsp; Macro language does not use quotes to identify strings of characters.&amp;nbsp; In combination, the new macro might look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro loop (gball=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %local k;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %do k=1 %to %sysfunc(countw(&amp;amp;gball));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %mb (%scan(&amp;amp;gball, &amp;amp;k))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;
&lt;P&gt;%mend loop;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then call it with (for example):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%loop (gball=123 456 789)&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 16:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-with-text-files/m-p/449045#M283548</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-27T16:02:59Z</dc:date>
    </item>
  </channel>
</rss>

