<?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 Importing monthly text files from the previous 12 months in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Importing-monthly-text-files-from-the-previous-12-months/m-p/600772#M16640</link>
    <description>&lt;P&gt;Hi!&lt;BR /&gt;&lt;BR /&gt;I would like to learn how to read in and stack files from the previous 12 months all at once. The files are monthly text files with a XX month lag (ex: If I were to run an analysis in October, I would pull files from June if XX=05, but if I were to run an analysis in November, I would pull files from July). I also need to pull files for each of the 12 months prior. All the files have a name like zz_MON_YYYY.txt.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Oct 2019 18:45:57 GMT</pubDate>
    <dc:creator>mb402</dc:creator>
    <dc:date>2019-10-31T18:45:57Z</dc:date>
    <item>
      <title>Importing monthly text files from the previous 12 months</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Importing-monthly-text-files-from-the-previous-12-months/m-p/600772#M16640</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;&lt;BR /&gt;I would like to learn how to read in and stack files from the previous 12 months all at once. The files are monthly text files with a XX month lag (ex: If I were to run an analysis in October, I would pull files from June if XX=05, but if I were to run an analysis in November, I would pull files from July). I also need to pull files for each of the 12 months prior. All the files have a name like zz_MON_YYYY.txt.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 18:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Importing-monthly-text-files-from-the-previous-12-months/m-p/600772#M16640</guid>
      <dc:creator>mb402</dc:creator>
      <dc:date>2019-10-31T18:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Importing monthly text files from the previous 12 months</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Importing-monthly-text-files-from-the-previous-12-months/m-p/600831#M16646</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255091"&gt;@mb402&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi!&lt;BR /&gt;&lt;BR /&gt;I would like to learn how to read in and stack files from the previous 12 months all at once. The files are monthly text files with a XX month lag (ex: If I were to run an analysis in October, I would pull files from June if XX=05, but if I were to run an analysis in November, I would pull files from July). I also need to pull files for each of the 12 months prior. All the files have a name like zz_MON_YYYY.txt.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Step one is write the code to read one file.&lt;/P&gt;
&lt;P&gt;Then you can make a design decision.&amp;nbsp; Do you want to write one data step that reads all 12 files at once?&amp;nbsp; Or read one file at a time and then combine the generated datasets.&lt;/P&gt;
&lt;P&gt;For the first option&amp;nbsp;modify the code to read from two files at once. Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename files ('zz_OCT_2019.txt','zz_SEP_2019.txt');
data want;
   infile files .... ;
....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the second option write the step that combines two of the files.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set month1 month2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See how to extend the pattern to 12 files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the issue of how to generate 12 months just use the INTNX() function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data months;
   start=today();
   do offset=0 to -11 by -1 ;
      next_month=intnx('month',start,offset);
      output;
  end;
  format start next_month date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 20:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Importing-monthly-text-files-from-the-previous-12-months/m-p/600831#M16646</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-31T20:29:02Z</dc:date>
    </item>
  </channel>
</rss>

