<?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 get the recent file with specific keyword in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751089#M236378</link>
    <description>&lt;P&gt;&lt;EM&gt;&amp;gt; What I need is to get the file with max date as suffix with specific keyword&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I see you sort the DIR results. Do you need the max date from the OS or from the file suffix?&lt;/P&gt;
&lt;P&gt;If you need by suffix as stated, there is no need to sort when running DIR, but you must sort when you have the file list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;What I need is to get the file with max date as suffix with specific keyword - QR&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Why not keep just these files, then you code would work as is. Maybe&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename xlsdir pipe "dir ""&amp;amp;xlsdir.\*QR*.xlsx"" /b /o:d /a:-d";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename xlsdir pipe "dir ""&amp;amp;xlsdir.\*.xlsx"" /b /o:d /a:-d | find ""QR"" ";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Jun 2021 22:51:55 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-06-29T22:51:55Z</dc:date>
    <item>
      <title>How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/750987#M236315</link>
      <description>&lt;P&gt;Hi Cohort,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have looked through the community's old responses for answers but couldn't find the one that I could not tailor for this requirement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I am using in windows to get the last modified file in windows.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%* identify the most recent response file;
%let xlsdir=C:\filedump;
filename xlsdir pipe "dir ""&amp;amp;xlsdir.\*.xlsx"" /b /o:d /a:-d";
data _null_; infile xlsdir truncover end=eof; input fname $255.; if eof then call symput('xlsfile',cats(fname)); run;
%put &amp;amp;xlsfile.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I need is to get the file with max date as suffix with specific keyword - QR - There are other files in the same folder with other keywords.&amp;nbsp;&lt;/P&gt;&lt;P&gt;File name formats:&lt;/P&gt;&lt;P&gt;FN_QR_Report_20210423.xlsx&lt;/P&gt;&lt;P&gt;EN_QR_Report_20210513.xlsx&lt;/P&gt;&lt;P&gt;TN_QR_Report_20210520.xlsx&lt;/P&gt;&lt;P&gt;I need&amp;nbsp;TN_QR_Report_20210520.xlsx to be assigned to&amp;nbsp;&lt;CODE class=" language-sas"&gt;&amp;amp;xlsfile.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;Thank you for your time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 15:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/750987#M236315</guid>
      <dc:creator>shasank</dc:creator>
      <dc:date>2021-06-29T15:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/750992#M236319</link>
      <description>&lt;P&gt;Can you get the filename in a variable and then extract the date and convert it to a SAS date? Store that in a variable and that sort by the date and then you can get the latest date.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 15:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/750992#M236319</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-29T15:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/750998#M236322</link>
      <description>Thank you for your response. That is what I was planning to do if that's the only way. But, wanted to ask the community for an efficient way to do this by adding one or two lines to the above code.</description>
      <pubDate>Tue, 29 Jun 2021 15:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/750998#M236322</guid>
      <dc:creator>shasank</dc:creator>
      <dc:date>2021-06-29T15:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/750999#M236323</link>
      <description>&lt;P&gt;&lt;A href="https://support.sas.com/kb/42/964.html" target="_blank"&gt;https://support.sas.com/kb/42/964.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 16:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/750999#M236323</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-29T16:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751001#M236324</link>
      <description>Thanks Mate. This is similar to the code that I am using to get the last modified date code posted above in the question.</description>
      <pubDate>Tue, 29 Jun 2021 16:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751001#M236324</guid>
      <dc:creator>shasank</dc:creator>
      <dc:date>2021-06-29T16:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751089#M236378</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; What I need is to get the file with max date as suffix with specific keyword&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I see you sort the DIR results. Do you need the max date from the OS or from the file suffix?&lt;/P&gt;
&lt;P&gt;If you need by suffix as stated, there is no need to sort when running DIR, but you must sort when you have the file list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;What I need is to get the file with max date as suffix with specific keyword - QR&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Why not keep just these files, then you code would work as is. Maybe&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename xlsdir pipe "dir ""&amp;amp;xlsdir.\*QR*.xlsx"" /b /o:d /a:-d";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename xlsdir pipe "dir ""&amp;amp;xlsdir.\*.xlsx"" /b /o:d /a:-d | find ""QR"" ";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 22:51:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751089#M236378</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-29T22:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751090#M236379</link>
      <description>&lt;P&gt;Also you should use &lt;FONT face="courier new,courier"&gt;call symputx()&lt;/FONT&gt; instead of &lt;FONT face="courier new,courier"&gt;cats()&lt;/FONT&gt; to trim trailing spaces.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 22:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751090#M236379</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-29T22:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751091#M236380</link>
      <description>&lt;P&gt;Note that you can sort and assign in one step. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
  select FNAME into :xlsfile from FILES having compress(FNAME,,'dk')=max(compress(FNAME,,'dk')); 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 23:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751091#M236380</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-06-29T23:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the recent file with specific keyword</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751130#M236410</link>
      <description>&lt;P&gt;If executing Powershell code is allowed, you could use&lt;/P&gt;
&lt;PRE&gt;Get-ChildItem *QR*.xlsx | Sort-Object LastWriteTime -Descending | Select-Object -First 1 FullName&lt;/PRE&gt;
&lt;P&gt;to get the latest file.&lt;/P&gt;
&lt;P&gt;See &lt;A href="https://blogs.sas.com/content/sasdummy/2011/09/15/calling-windows-powershell-from-sas-a-simple-example/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2011/09/15/calling-windows-powershell-from-sas-a-simple-example/&lt;/A&gt; for details about executing ps from sas.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 05:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-recent-file-with-specific-keyword/m-p/751130#M236410</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-06-30T05:59:10Z</dc:date>
    </item>
  </channel>
</rss>

