<?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: Reading Multiple files with the same naming convention for the last 12 months and consolidating in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516837#M73284</link>
    <description>&lt;P&gt;A far easier way to do what you want would be to move all of your monthly SAS datasets into one folder and rename each of them with a monthly suffix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then to consolidate 12 months all you need to do is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set MySASLib.&lt;SPAN&gt;List_R_G&lt;/SPAN&gt;_201701 - MySASLib.&lt;SPAN&gt;List_R_G&lt;/SPAN&gt;_201712;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 28 Nov 2018 19:29:17 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2018-11-28T19:29:17Z</dc:date>
    <item>
      <title>Reading Multiple files with the same naming convention for the last 12 months and consolidating them</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516538#M73270</link>
      <description>&lt;P&gt;Hello Friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Somewhat of a beginner here.... I have a task that requires me to consolidate datasets for the previous 12 months before I proceed with the ask.&lt;/P&gt;&lt;P&gt;Example: I have an October Dataset and I would need to compare it against the previous 12 months. I know how to manually specify each dataset and then consolidate but that is tedious and ugly.&lt;/P&gt;&lt;P&gt;Therefore, I would like to specify the month and year and then have the script pull the previous 12 months of the data.&lt;/P&gt;&lt;P&gt;The datasets are all named the same: List_R_G but they reside in folders for different months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no clue where to start. Could someone please assist ? Hopefully, my question makes sense&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 01:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516538#M73270</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2018-11-28T01:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Multiple files with the same naming convention for the last 12 months and consolidating</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516540#M73271</link>
      <description>1. Make a list of the file paths where the file will be. &lt;BR /&gt;2. In a data step, there's an option on the INFILE statement, FILEVAR. &lt;BR /&gt;&lt;BR /&gt;See Example 5 in the documentation. &lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1x9joj5qbfkjyn1kqtm7joru0qb" target="_blank"&gt;https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1x9joj5qbfkjyn1kqtm7joru0qb&lt;/A&gt;</description>
      <pubDate>Wed, 28 Nov 2018 01:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516540#M73271</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-28T01:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Multiple files with the same naming convention for the last 12 months and consolidating</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516580#M73273</link>
      <description>&lt;P&gt;Thank you so much for the response Reeza. However, this is my concern. The code you directed me to asks me to specify the file location. Meaning, I would to change this every month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally, what I would like to do is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Month = November&lt;/P&gt;&lt;P&gt;Year = 2018&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;have the query written so it goes back 12 months a picks all the files... So, technically if I change the month and year, it should compute back 12 months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is that possible ? As I said, the pathname is the same. It is just different folders in the format YYYY-MM that houses the datasets. Dataset names are the same as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly advise and thank you very much again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 05:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516580#M73273</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2018-11-28T05:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Multiple files with the same naming convention for the last 12 months and consolidating</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516751#M73278</link>
      <description>You use a data step to create a list of the file names using a loop and INTNX(). This is dynamic so you can use TODAY() to get the date today and then use string functions to make the file path. Functions are pretty much all you need here, INTNX(), TODAY(), MONTH(), YEAR(), CATT() or CATX().</description>
      <pubDate>Wed, 28 Nov 2018 16:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516751#M73278</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-28T16:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Multiple files with the same naming convention for the last 12 months and consolidating</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516837#M73284</link>
      <description>&lt;P&gt;A far easier way to do what you want would be to move all of your monthly SAS datasets into one folder and rename each of them with a monthly suffix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then to consolidate 12 months all you need to do is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set MySASLib.&lt;SPAN&gt;List_R_G&lt;/SPAN&gt;_201701 - MySASLib.&lt;SPAN&gt;List_R_G&lt;/SPAN&gt;_201712;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 19:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516837#M73284</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-11-28T19:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Multiple files with the same naming convention for the last 12 months and consolidating</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516841#M73285</link>
      <description>&lt;P&gt;What code do you want to generate?&amp;nbsp; Is it something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set
  "&amp;amp;top/2018-11/list_r_g"
  "&amp;amp;top/2018-10/list_r_g"
  "&amp;amp;top/2018-09/list_r_g"
  "&amp;amp;top/2018-08/list_r_g"
  "&amp;amp;top/2018-07/list_r_g"
  "&amp;amp;top/2018-06/list_r_g"
  "&amp;amp;top/2018-05/list_r_g"
  "&amp;amp;top/2018-04/list_r_g"
  "&amp;amp;top/2018-03/list_r_g"
  "&amp;amp;top/2018-02/list_r_g"
  "&amp;amp;top/2018-01/list_r_g"
  "&amp;amp;top/2017-12/list_r_g"
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could write a simple data step to generate that list into a macro variable. You could then use it in your SET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length name list $500 ;
  do i=0 to -11 by -1 ;
     date = intnx('month',today(),i,'b');
     name = quote(catx('/','&amp;amp;top',substr(put(date,yymmdd10.),1,7),'list_r_g'));
     list = catx(' ', list , name);
  end;
  call symputx('list',list);
run;
%let top=/my/top/level/folder;
data want;
  set &amp;amp;list;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 19:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/516841#M73285</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-28T19:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Multiple files with the same naming convention for the last 12 months and consolidating</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/517728#M73316</link>
      <description>&lt;P&gt;Oh, that is clever! Not what I am looking for in this case but I will be using that for another task. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 07:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/517728#M73316</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2018-12-01T07:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Multiple files with the same naming convention for the last 12 months and consolidating</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/517730#M73317</link>
      <description>Thank you Tom. I shall attempt this tomorrow. To answer your question, once a month I have to generate a dataset that has unique values (not appearing in the previous 12 months). So, as a first step I wanted to have a macro that pulls and consolidates the files for the previous 12 months. I just want to be able to specify a month and year and then have the macro work backwards.</description>
      <pubDate>Sat, 01 Dec 2018 07:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/517730#M73317</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2018-12-01T07:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Multiple files with the same naming convention for the last 12 months and consolidating</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/517733#M73318</link>
      <description>Thank you Reeza. I confess that I didn't understand all that. But I will look it up and learn more. I am familiar with intx() and the other functions except catt and catx. The problem is using it in the right context. I am still a new user that is more familiar with pulling data rather than manipulating and stitching it in different ways.</description>
      <pubDate>Sat, 01 Dec 2018 07:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reading-Multiple-files-with-the-same-naming-convention-for-the/m-p/517733#M73318</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2018-12-01T07:32:48Z</dc:date>
    </item>
  </channel>
</rss>

