<?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: Read in the last 3 files from folder SAS EG in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708800#M37924</link>
    <description>&lt;P&gt;Note that MEMNAME field is always in uppercase.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname='MYLIB' and memname like 'OUTREACH^_%' escape '^'&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Dec 2020 21:00:17 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-12-30T21:00:17Z</dc:date>
    <item>
      <title>Read in the last 3 files from folder SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708790#M37922</link>
      <description>&lt;P&gt;I have a folder where a new file is put every 2 weeks and at start of the month i have to pull the last three files from that folder into a sas code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The data is never the same there are mostly 2 files in one and i need to pull a file from the month before that. what the datafiles look like in my folder. Currently the folder has these files&lt;/P&gt;&lt;P&gt;outreach_201030.sas7bdat&lt;/P&gt;&lt;P&gt;outreach_201113.sas7bdat&lt;/P&gt;&lt;P&gt;outreach_201127.sas7bdat&lt;/P&gt;&lt;P&gt;outreach_201211.sas7bdat&lt;/P&gt;&lt;P&gt;outreach_201225.sas7bdat&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example in Jan 2021 I would need to pull the last file. Which are the two file from Dec 2020 and the last file from Nov 2020.&lt;/P&gt;&lt;P&gt;outreach_201127.sas7bdat&lt;/P&gt;&lt;P&gt;outreach_201211.sas7bdat&lt;/P&gt;&lt;P&gt;outreach_201225.sas7bdat&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an automated way to pull these files without me having to go in and changing the dates manually.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 18:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708790#M37922</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2020-12-30T18:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Read in the last 3 files from folder SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708796#M37923</link>
      <description>&lt;P&gt;If your files are strictly sas datasets, the following will work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname MYLIB "FOLDER_PATH_HERE";
proc sql outobs=3;
	create table want as
	select memname 
	from dictionary.tables 
	where libname='MYLIB' and memtype='DATA' and memname like 'OUTREACH%'
	order by memname desc;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Establish a library MYLIB using your folder location.&lt;/P&gt;
&lt;P&gt;Use DICTIONARY.TABLES to list all tables within MYLIB.&lt;/P&gt;
&lt;P&gt;Order by descending memname so that the most recent files are first.&lt;/P&gt;
&lt;P&gt;Use the OUTOBS option to limit the output to 3 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From here, you can place the results into macro variables (FILE_1, FILE_2, FILE_3) by doing the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select memname into :FILE_1 - :FILE_3
	from want;
quit;
%put &amp;amp;=file_1 &amp;amp;=file_2 &amp;amp;=file_3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the names of the datasets can be accessed with &amp;amp;FILE_1, &amp;amp;FILE_2, &amp;amp;FILE_3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 21:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708796#M37923</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-12-30T21:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Read in the last 3 files from folder SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708800#M37924</link>
      <description>&lt;P&gt;Note that MEMNAME field is always in uppercase.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname='MYLIB' and memname like 'OUTREACH^_%' escape '^'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Dec 2020 21:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708800#M37924</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-30T21:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Read in the last 3 files from folder SAS EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708809#M37925</link>
      <description>&lt;P&gt;Good catch, thanks Tom!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 21:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Read-in-the-last-3-files-from-folder-SAS-EG/m-p/708809#M37925</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-12-30T21:53:36Z</dc:date>
    </item>
  </channel>
</rss>

