<?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: How to use macro for infile multiple txt? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/609012#M76700</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302002"&gt;@dupp99&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I need to do them using the macro. How could I do them using macro?&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, no, as demonstrated above, you do not need a macro. It's just extra complications (as you have found) for no benefit.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Dec 2019 11:33:33 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-12-03T11:33:33Z</dc:date>
    <item>
      <title>How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608895#M76690</link>
      <description>&lt;DIV class="page"&gt;&lt;DIV class="layoutArea"&gt;&lt;DIV class="column"&gt;&lt;P&gt;&lt;SPAN&gt;I want the macro to have one parameter which is the path of the text files.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have now. I have 6 txt with name= NY2012.txt &amp;nbsp; NY2013.txt &amp;nbsp; NY2014.txt.....etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro data ;

%let list= 2012 2013 2014 2015 2016 2017;


data allData;
delete; &amp;nbsp;(what should I put here?)
run;


%do i=1 %to 6;
%let currItem = %scan(&amp;amp;list, &amp;amp;i);&lt;BR /&gt;
filename f&amp;amp;list "/folders/myfolders/NY&amp;amp;list.txt"; (should this be here?)
data currentData;
x = &amp;amp;currItem;

infile f&amp;amp;list &amp;nbsp;truncover;
input value $ 1-20;
retain year;
if _n_=1 then year=year_1;

run;

* Keeping adding things to the cumulative data set;
data allData;
set allData currentData;
run;
%end;

%mend data;

%data;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I should end up with a dataset for each year and one large dataset that included all the years. How should I fix this? Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 23:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608895#M76690</guid>
      <dc:creator>dupp99</dc:creator>
      <dc:date>2019-12-02T23:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608897#M76691</link>
      <description>&lt;P&gt;Why not use a wildcard * in the filename.&amp;nbsp; Then use the EOV and FILENAME INFILE statement options to know the data source.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 00:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608897#M76691</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-12-03T00:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608898#M76692</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename f&amp;amp;list "/folders/myfolders/NY&amp;amp;list.txt";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;replace the above with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename flist "/folders/myfolders/NY*.txt";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No macro needed. This command reads all files NY*.txt at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if the variable names are the same (and variable types are the same) in all the NY*.txt files, use PROC APPEND rather than a SET command in a DATA step to append.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 00:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608898#M76692</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-03T00:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608901#M76693</link>
      <description>&lt;P&gt;To delete a dataset use PROC DELETE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc delete data=alldata; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the FILEVAR= option on the INFILE statement to tell SAS to use the value of the named varaible as the name of the file to read.&lt;/P&gt;
&lt;P&gt;If your list of values is separated by commas you can use them in a DO statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do year=2012,2013,2014,2015,2016,2017;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it also looks like list is just all years from 2012 to 2017.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do year=2012 to 2017;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So putting it together here is how you could do it without any macro logic at all.&amp;nbsp; But perhaps just a single macro function call to change the space delimited list into a comma delimited list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list= 2012 2013 2014 2015 2016 2017;
%let listcomma=%sysfunc(translate(&amp;amp;list,%str(,),%str( )));

data alldata ;
  do year=&amp;amp;listcomma ;
     length fname $200 ;
     fname = cats("/folders/myfolders/NY",year,".txt");
     infile txt filevar=fname end=eof truncover;
     do while(not eof);
       input value $20. ;
       output;
     end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2019 00:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608901#M76693</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-03T00:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608926#M76695</link>
      <description>&lt;P&gt;I need to do them using the macro. I think what I wrote is almost right, use needs some small changes. Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 04:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608926#M76695</guid>
      <dc:creator>dupp99</dc:creator>
      <dc:date>2019-12-03T04:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608931#M76697</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I need to do them using the macro. How could I do them using macro?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 05:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608931#M76697</guid>
      <dc:creator>dupp99</dc:creator>
      <dc:date>2019-12-03T05:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608932#M76698</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I need to do them using the macro. How could I do them using macro? or make more changes based on the codes I wrote. Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 05:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608932#M76698</guid>
      <dc:creator>dupp99</dc:creator>
      <dc:date>2019-12-03T05:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608948#M76699</link>
      <description>&lt;P&gt;NO MACRO IS NEEDED.&lt;/P&gt;
&lt;P&gt;One only uses macro coding if it is absolutely necessary; in your case it isn't.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has shown a complete solution in one data step.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 06:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/608948#M76699</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-03T06:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/609012#M76700</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302002"&gt;@dupp99&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I need to do them using the macro. How could I do them using macro?&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, no, as demonstrated above, you do not need a macro. It's just extra complications (as you have found) for no benefit.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 11:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/609012#M76700</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-03T11:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro for infile multiple txt?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/609013#M76701</link>
      <description>Before you can use a macro to generate code you have to know what code you need to generate.  So work on getting code to work for one file.  Then you could think about building a macro (if one is needed).&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Dec 2019 11:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-macro-for-infile-multiple-txt/m-p/609013#M76701</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-03T11:34:18Z</dc:date>
    </item>
  </channel>
</rss>

