<?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 file and add last modified date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944104#M369962</link>
    <description>&lt;P&gt;Use this macro:&amp;nbsp; &lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of just read the macro to see how it is finding the date for each file. Basically you have to open each file so that you can use the FINFO() function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that FINFO() wants the NAME of the option passed to it, but the name it wants depends on the language settings of your session, so use the FOPTNAME() function to find the right name to use.&amp;nbsp; Also the string returned depends on the language setting, so use the right informat to convert to a value datetime value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;      lastmod = input(finfo(fid,foptname(fid, 5)), nldatm100.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Sep 2024 15:46:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-09-16T15:46:39Z</dc:date>
    <item>
      <title>Read file and add last modified date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944073#M369955</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have this logic to retrieve all file inside a folder, I want to add last modified or created date of the file inside.&lt;/P&gt;&lt;P&gt;Where can I add and what procedure to use? Thanks&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/*FIND PATH PARENT*/
%let pathbase=G:\Shared drives\;
data filebase;
length fref $8 fname $200;
did = filename(fref,"&amp;amp;pathbase.");
did = dopen(fref);
do i = 1 to dnum(did);
	fname = dread(did,i);
output;
end;
did = dclose(did);
did = filename(fref);
keep fname i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="febyinkasid_0-1726493825070.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100382i9606A0F1CAFEA213/image-size/medium?v=v2&amp;amp;px=400" role="button" title="febyinkasid_0-1726493825070.png" alt="febyinkasid_0-1726493825070.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 13:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944073#M369955</guid>
      <dc:creator>febyinkasid</dc:creator>
      <dc:date>2024-09-16T13:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Read file and add last modified date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944090#M369956</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464693"&gt;@febyinkasid&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p023sn4hgjgvpjn19ozlet62e0up.htm" target="_blank" rel="noopener"&gt;MOPEN&lt;/A&gt;, &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0cpuq4ew0dxipn1vtravlludjm7.htm" target="_blank" rel="noopener"&gt;FINFO&lt;/A&gt; and &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0ihcrv5rt8mw4n16kqi1p9caq6i.htm" target="_blank" rel="noopener"&gt;FCLOSE&lt;/A&gt; functions:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#808080"&gt;/*FIND PATH PARENT*/
%let pathbase=G:\Shared drives\;
data filebase;
length fref $8 fname $200;
did = filename(fref,"&amp;amp;pathbase.");
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  &lt;FONT color="#000000"&gt;&lt;STRONG&gt;fid=mopen(did, fname);
  created=input(finfo(fid,'Create Time'),nldatm200.);
  lastmod=input(finfo(fid,'Last Modified'),nldatm200.);
  rc=fclose(fid);&lt;/STRONG&gt;&lt;/FONT&gt;
output;
end;
did = dclose(did);
did = filename(fref);
&lt;FONT color="#000000"&gt;&lt;STRONG&gt;format created lastmod e8601dt.;&lt;/STRONG&gt;&lt;/FONT&gt;
keep fname i &lt;FONT color="#000000"&gt;&lt;STRONG&gt;created lastmod&lt;/STRONG&gt;&lt;/FONT&gt;;
run;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Sep 2024 14:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944090#M369956</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-09-16T14:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: Read file and add last modified date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944094#M369958</link>
      <description>&lt;P&gt;Hi, Thank You...&lt;/P&gt;&lt;P&gt;I cant retrieve the date, though there is no error in log&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="febyinkasid_0-1726499501500.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100390i18F62B3EE9733175/image-size/medium?v=v2&amp;amp;px=400" role="button" title="febyinkasid_0-1726499501500.png" alt="febyinkasid_0-1726499501500.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 15:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944094#M369958</guid>
      <dc:creator>febyinkasid</dc:creator>
      <dc:date>2024-09-16T15:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Read file and add last modified date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944100#M369960</link>
      <description>&lt;P&gt;It worked with a local directory on my Windows workstation. What does the PUT statement write to the log if you add it like in the modified code below?&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#808080"&gt;data filebase;
length fref $8 fname &lt;STRONG&gt;&lt;FONT color="#000000"&gt;created lastmod&lt;/FONT&gt;&lt;/STRONG&gt; $200;
did = filename(fref,"&amp;amp;pathbase.");
did = dopen(fref);
do i = 1 to dnum(did);
  fname = dread(did,i);
  fid=mopen(did, fname);
  &lt;FONT color="#000000"&gt;&lt;STRONG&gt;put fid=;&lt;/STRONG&gt;
&lt;STRONG&gt;  created=finfo(fid,'Create Time');
  lastmod=finfo(fid,'Last Modified');&lt;/STRONG&gt;&lt;/FONT&gt;
  rc=fclose(fid);
output;
end;
did = dclose(did);
did = filename(fref);
keep fname i created lastmod;
run;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;I've also simplified the assignment statements for the two new variables by using their default (character!) format. Note the deletion of the FORMAT statement.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 15:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944100#M369960</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-09-16T15:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Read file and add last modified date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944104#M369962</link>
      <description>&lt;P&gt;Use this macro:&amp;nbsp; &lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of just read the macro to see how it is finding the date for each file. Basically you have to open each file so that you can use the FINFO() function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that FINFO() wants the NAME of the option passed to it, but the name it wants depends on the language settings of your session, so use the FOPTNAME() function to find the right name to use.&amp;nbsp; Also the string returned depends on the language setting, so use the right informat to convert to a value datetime value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;      lastmod = input(finfo(fid,foptname(fid, 5)), nldatm100.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 15:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944104#M369962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-16T15:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read file and add last modified date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944556#M370078</link>
      <description>&lt;P&gt;Oooh it workss! I think I wrote a path that consists of folder thats why.&lt;/P&gt;&lt;P&gt;Thank You so much&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 06:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-file-and-add-last-modified-date/m-p/944556#M370078</guid>
      <dc:creator>febyinkasid</dc:creator>
      <dc:date>2024-09-19T06:19:32Z</dc:date>
    </item>
  </channel>
</rss>

