<?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: A macro that can read files with different date everyday in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712347#M27015</link>
    <description>&lt;P&gt;See this quick data step to read all files from a directory and get their last modification timestamp:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dir=/folders/myfolders;

data dir;
length
  fref dref $8
  fname $200
;
format dt e8601dt19.;
rc = filename(dref,"&amp;amp;dir.");
did = dopen(dref);
do i = 1 to dnum(did);
  fname = catx("/","&amp;amp;dir.",dread(did,i));
  rc = filename(fref,fname);
  fid = fopen(fref);
  if fid ne 0
  then do;
    dt = input(finfo(fid,foptname(fid,5)),nldatm40.);
    output;
    rc = fclose(fid);
  end;
  else do;
    err = sysmsg();
    put _all_;
  end;
end;
rc = dclose(did);
keep fname dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then either sort by name or dt to get the latest file, or select for a given name with a given date in it.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jan 2021 08:59:04 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-01-19T08:59:04Z</dc:date>
    <item>
      <title>A macro that can read files with different date everyday</title>
      <link>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712332#M27012</link>
      <description>&lt;P&gt;Hi.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a duty to send out data everyday to a reciever.&lt;/P&gt;
&lt;P&gt;I want to make this code good for automatisation&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a macro where It reads the file name with different dates every day, without me changing the filename?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the filename could be something like this today: test_data_2021-01-19, and tomorrow&amp;nbsp;test_data_2021-01-20&lt;/P&gt;
&lt;P&gt;I also have file without the date, so a macro that also can search for the latest file in a directory?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it is understandable&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 07:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712332#M27012</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-01-19T07:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: A macro that can read files with different date everyday</title>
      <link>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712338#M27013</link>
      <description>&lt;P&gt;You are not really clear about this.&lt;/P&gt;
&lt;P&gt;Do you &lt;EM&gt;receive&lt;/EM&gt; files for &lt;EM&gt;importing&lt;/EM&gt; into SAS, or do you need to &lt;EM&gt;export&lt;/EM&gt; data to external files for &lt;EM&gt;sending&lt;/EM&gt; them to someone else?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 07:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712338#M27013</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-19T07:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: A macro that can read files with different date everyday</title>
      <link>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712340#M27014</link>
      <description>&lt;P&gt;i receive files from someone into a directory, everyday - and everyday I use these files into my SAS program to come out with a result for them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 07:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712340#M27014</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-01-19T07:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: A macro that can read files with different date everyday</title>
      <link>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712347#M27015</link>
      <description>&lt;P&gt;See this quick data step to read all files from a directory and get their last modification timestamp:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dir=/folders/myfolders;

data dir;
length
  fref dref $8
  fname $200
;
format dt e8601dt19.;
rc = filename(dref,"&amp;amp;dir.");
did = dopen(dref);
do i = 1 to dnum(did);
  fname = catx("/","&amp;amp;dir.",dread(did,i));
  rc = filename(fref,fname);
  fid = fopen(fref);
  if fid ne 0
  then do;
    dt = input(finfo(fid,foptname(fid,5)),nldatm40.);
    output;
    rc = fclose(fid);
  end;
  else do;
    err = sysmsg();
    put _all_;
  end;
end;
rc = dclose(did);
keep fname dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then either sort by name or dt to get the latest file, or select for a given name with a given date in it.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 08:59:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712347#M27015</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-19T08:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: A macro that can read files with different date everyday</title>
      <link>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712355#M27017</link>
      <description>&lt;P&gt;For a file with different dates - where in the code could I state that&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 09:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712355#M27017</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-01-19T09:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: A macro that can read files with different date everyday</title>
      <link>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712361#M27019</link>
      <description>&lt;P&gt;You use a simple IF condition with SUBSTR() or SCAN() of the filename.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2021 09:21:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/A-macro-that-can-read-files-with-different-date-everyday/m-p/712361#M27019</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-19T09:21:45Z</dc:date>
    </item>
  </channel>
</rss>

