<?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 Select latest dataset file every month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473855#M121651</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've a requirement to read files from a folder every month. So for example if I run the program in June, it should read the file from May. Likewise if I run the program in July, it should read the file from June.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data file (&lt;STRONG&gt;Excel worksheet)&lt;/STRONG&gt; is stored as:&lt;/P&gt;&lt;P&gt;XYZ_050118&lt;/P&gt;&lt;P&gt;XYZ_040118&lt;/P&gt;&lt;P&gt;XYZ_030118&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest how I can read the latest file based on the "timestamp" on the file and choose the latest file every month?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated. Thank you!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 18:20:54 GMT</pubDate>
    <dc:creator>SteelersPitts</dc:creator>
    <dc:date>2018-06-27T18:20:54Z</dc:date>
    <item>
      <title>Select latest dataset file every month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473855#M121651</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've a requirement to read files from a folder every month. So for example if I run the program in June, it should read the file from May. Likewise if I run the program in July, it should read the file from June.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data file (&lt;STRONG&gt;Excel worksheet)&lt;/STRONG&gt; is stored as:&lt;/P&gt;&lt;P&gt;XYZ_050118&lt;/P&gt;&lt;P&gt;XYZ_040118&lt;/P&gt;&lt;P&gt;XYZ_030118&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest how I can read the latest file based on the "timestamp" on the file and choose the latest file every month?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated. Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 18:20:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473855#M121651</guid>
      <dc:creator>SteelersPitts</dc:creator>
      <dc:date>2018-06-27T18:20:54Z</dc:date>
    </item>
    <item>
      <title>SELECT MONTHLY DATA FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473853#M121666</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've a requirement to read files from a folder every month. So for example if I run the program in June, it should read the file from May. Likewise if I run the program in July, it should read the file from June.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data file is stored as:&lt;/P&gt;&lt;P&gt;XYZ_050118&lt;/P&gt;&lt;P&gt;XYZ_040118&lt;/P&gt;&lt;P&gt;XYZ_030118&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest how I can read the latest file based on the "timestamp" on the file and choose the latest file every month?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated. Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 18:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473853#M121666</guid>
      <dc:creator>SteelersPitts</dc:creator>
      <dc:date>2018-06-27T18:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Select latest dataset file every month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473859#M121653</link>
      <description>&lt;P&gt;If they are SAS datasets stored in a library, You could query dictionary tables aka sashelp.vtable and filter using datecreated variable for the previous month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 18:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473859#M121653</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-27T18:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Select latest dataset file every month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473860#M121654</link>
      <description>&lt;P&gt;The files are excel worksheet. Sorry, I missed that information. I've updated the post.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 18:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473860#M121654</guid>
      <dc:creator>SteelersPitts</dc:creator>
      <dc:date>2018-06-27T18:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT MONTHLY DATA FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473895#M121667</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
lastmonth=put(intnx('month',"%sysfunc(today(),DATE9.)"d,-1),MMYYC5.);
mm=scan(lastmonth,1,':');
yy=scan(lastmonth,2,':');
fullname='XYZ_'||strip(mm)||'01'||strip(yy);
call symputx('filestr',fullname);
run;

%put Last months file = &amp;amp;filestr;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Assuming the folder you're referring to is a SAS library, use the libname and &amp;amp;filestr macro var to access last month's file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 19:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473895#M121667</guid>
      <dc:creator>ChanceTGardener</dc:creator>
      <dc:date>2018-06-27T19:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Select latest dataset file every month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473948#M121694</link>
      <description>&lt;P&gt;1. Calculate the file stamp of the file you need. This creates a macro variable that you can use in the path of your file name in the import.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let prev_month = %sysfunc(intnx(month,%sysfunc(date()),-1),mmddyy6.);

%put &amp;amp;prev_month;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Use FEXIST() to check if the file exists first.&lt;/P&gt;
&lt;P&gt;3. Import file as desired.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import out=want datafile="path to file/XYZ_&amp;amp;prev_month..xlsx" dbms=xlsx replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175426"&gt;@SteelersPitts&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've a requirement to read files from a folder every month. So for example if I run the program in June, it should read the file from May. Likewise if I run the program in July, it should read the file from June.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data file (&lt;STRONG&gt;Excel worksheet)&lt;/STRONG&gt; is stored as:&lt;/P&gt;
&lt;P&gt;XYZ_050118&lt;/P&gt;
&lt;P&gt;XYZ_040118&lt;/P&gt;
&lt;P&gt;XYZ_030118&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone suggest how I can read the latest file based on the "timestamp" on the file and choose the latest file every month?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated. Thank you!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jun 2018 01:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/473948#M121694</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-28T01:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT MONTHLY DATA FILES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/474449#M121911</link>
      <description>&lt;P&gt;Thank you for your prompt response!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 14:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-latest-dataset-file-every-month/m-p/474449#M121911</guid>
      <dc:creator>SteelersPitts</dc:creator>
      <dc:date>2018-06-29T14:31:43Z</dc:date>
    </item>
  </channel>
</rss>

