<?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 read latest flat file based on date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335501#M75949</link>
    <description>&lt;P&gt;thank you, let me try&lt;/P&gt;</description>
    <pubDate>Fri, 24 Feb 2017 04:23:51 GMT</pubDate>
    <dc:creator>SAS_INFO</dc:creator>
    <dc:date>2017-02-24T04:23:51Z</dc:date>
    <item>
      <title>how to read latest flat file based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335491#M75937</link>
      <description>&lt;P&gt;hi SAS Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In a location i have lot of flat files, appended weekly basis(not regular).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have connected the path and there is a code to import yesterday's file. But hat i need is to import any latest file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ex. ET002A.D170220.abc.txt fen 20 is the latest,but for &amp;nbsp;ET002B.d170219.abc.txt feb 19th is the latest file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ET00 is common prefix and for each type like 2A, 2B,3H etc the file may be or may be not available for everyday.&lt;/P&gt;&lt;P&gt;so i need to import the latest file available for all the types .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please guide&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 03:14:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335491#M75937</guid>
      <dc:creator>SAS_INFO</dc:creator>
      <dc:date>2017-02-24T03:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to read latest flat file based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335496#M75940</link>
      <description>&lt;P&gt;anybody....&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 03:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335496#M75940</guid>
      <dc:creator>SAS_INFO</dc:creator>
      <dc:date>2017-02-24T03:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to read latest flat file based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335498#M75941</link>
      <description>&lt;P&gt;The following macro can list all files within a directory. With it, you can identify all of the possible file, then do a proc sort with the nodupkey option, using:&lt;/P&gt;
&lt;P&gt;by descending name;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If recency is totally identified by file name, then that should give you what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro list_files(dir=,ext=,sub=);
  %local filrf rc did memcnt name i;
  %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
  %let did=%sysfunc(dopen(&amp;amp;filrf));      

  %if &amp;amp;did eq 0 %then %do; 
    %put Directory &amp;amp;dir cannot be open or does not exist;
    %return;
  %end;

  %do i = 1 %to %sysfunc(dnum(&amp;amp;did));   

    %let name=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));

    %if %qupcase(%qscan(&amp;amp;name,-1,.)) = %upcase(&amp;amp;ext) %then %do;
      %if %qscan(&amp;amp;name,2,.) ne %then %do;
        %put &amp;amp;dir\&amp;amp;name;

        data _tmp;
          length dir $512 name $100;
          dir=symget("dir");
          name=symget("name");
        run;
        proc append base=want data=_tmp;
        run;

      %end;
    %end;
    %else %do;
      %if %upcase(&amp;amp;sub) eq 'YES' %then %do;
        %if %qscan(&amp;amp;name,2,.) = %then %do;        
          %list_files(dir=&amp;amp;dir\&amp;amp;name,ext=&amp;amp;ext,sub=&amp;amp;sub)
        %end;
      %end;
    %end;
  %end;
  %let rc=%sysfunc(dclose(&amp;amp;did));
  %let rc=%sysfunc(filename(filrf));     

%mend list_files;

proc delete data=want;
run;
%list_files(dir=C:\art,ext=sas,sub='no')

&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 04:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335498#M75941</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-24T04:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to read latest flat file based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335499#M75942</link>
      <description>&lt;P&gt;Look at the SAS macro's available in the Appendix,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n02xowj8yuqfo4n0zzi98shu8qup.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n02xowj8yuqfo4n0zzi98shu8qup.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They have useful ones including one that lists the file information for a specific directory.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 04:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335499#M75942</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-24T04:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to read latest flat file based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335501#M75949</link>
      <description>&lt;P&gt;thank you, let me try&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 04:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335501#M75949</guid>
      <dc:creator>SAS_INFO</dc:creator>
      <dc:date>2017-02-24T04:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to read latest flat file based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335539#M75966</link>
      <description>&lt;P&gt;In your specific case the date is part of the filename and in a format of YYMMDD which enable sorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other case, there is a possibility to get the Last Modifid date of the file programatically,&lt;/P&gt;
&lt;P&gt;using functio FINFO. Pay attention that list of attributes available and their names are different per Operating System.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The next code enables to get the list of attributes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path = /folders/myshortcuts/My_Folders/sas_help/; /* SAS UE on linux example */
%let fname = test20.sas;           /* addapt to an existing file you have */
%put NAME= &amp;amp;path.&amp;amp;fname;           /* check full path and filename */

data _null_;
   rc=filename('tmp',"&amp;amp;path.&amp;amp;fname");
   fid = fopen('tmp'); 
   put fid=;
   if fid then do;
        infonum = foptnum(fid); put infonum=;
        do i=1 to infonum;
           infoname = foptname(fid,i);
           fattr = finfo(fid,infoname); 
           put i= infoname = @33 fattr=;
        end; 
   end;       
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then in my OS I can get the Last Modified date by:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;modified_datetimex = finfo(fid,'Last Modified');
modified_datetime   = input(modified_datetimex, datetime18.);
modified_date = datepart(modified_datetime);
format modified_datetime datetime18. modifed_date date9.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Feb 2017 09:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-read-latest-flat-file-based-on-date/m-p/335539#M75966</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-24T09:53:50Z</dc:date>
    </item>
  </channel>
</rss>

