<?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: Files Presence and Details in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970589#M377101</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466540"&gt;@Aashi07&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works on my Windows workstation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create sample data for demonstration */

data have;
input name :$200.;
cards;
test.sas7bdat
test0.lst
test1.log
test2.sas
;

/* Check existence and retrieve last modification date of the above files in a specified folder */

%let folder=C:\Temp\test;

data want;
length path $260 fref $8;
set have;
path="&amp;amp;folder\"||name;
exists=fileexist(path);
if exists then do;
  rc=filename(fref,path);
  fid=fopen(fref);
  lastmod=input(finfo(fid,'Last Modified'),nldate200.);
  rc=fclose(fid);
end;
format lastmod yymmdd10.;
keep path exists lastmod;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Increase the lengths of variables NAME and PATH if necessary. Note that the "last modified" date is actually a &lt;EM&gt;datetime&lt;/EM&gt;, so you could read it with the &lt;FONT face="courier new,courier"&gt;nldat&lt;STRONG&gt;m&lt;/STRONG&gt;200.&lt;/FONT&gt; informat (in the INPUT function call) and use a datetime format such as &lt;FONT face="courier new,courier"&gt;e8601dt.&lt;/FONT&gt; in the FORMAT statement.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Jul 2025 10:26:57 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2025-07-11T10:26:57Z</dc:date>
    <item>
      <title>Files Presence and Details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970588#M377100</link>
      <description>&lt;P&gt;how can i check if a list of files is found in a folder and if found, access the date modified?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2025 09:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970588#M377100</guid>
      <dc:creator>Aashi07</dc:creator>
      <dc:date>2025-07-11T09:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Files Presence and Details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970589#M377101</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466540"&gt;@Aashi07&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works on my Windows workstation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create sample data for demonstration */

data have;
input name :$200.;
cards;
test.sas7bdat
test0.lst
test1.log
test2.sas
;

/* Check existence and retrieve last modification date of the above files in a specified folder */

%let folder=C:\Temp\test;

data want;
length path $260 fref $8;
set have;
path="&amp;amp;folder\"||name;
exists=fileexist(path);
if exists then do;
  rc=filename(fref,path);
  fid=fopen(fref);
  lastmod=input(finfo(fid,'Last Modified'),nldate200.);
  rc=fclose(fid);
end;
format lastmod yymmdd10.;
keep path exists lastmod;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Increase the lengths of variables NAME and PATH if necessary. Note that the "last modified" date is actually a &lt;EM&gt;datetime&lt;/EM&gt;, so you could read it with the &lt;FONT face="courier new,courier"&gt;nldat&lt;STRONG&gt;m&lt;/STRONG&gt;200.&lt;/FONT&gt; informat (in the INPUT function call) and use a datetime format such as &lt;FONT face="courier new,courier"&gt;e8601dt.&lt;/FONT&gt; in the FORMAT statement.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2025 10:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970589#M377101</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-07-11T10:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Files Presence and Details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970773#M377152</link>
      <description>I am using Unix</description>
      <pubDate>Tue, 15 Jul 2025 08:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970773#M377152</guid>
      <dc:creator>Aashi07</dc:creator>
      <dc:date>2025-07-15T08:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Files Presence and Details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970774#M377153</link>
      <description>&lt;P&gt;The code is pure SAS code and will work with minor modifications (path and FINFO item name/format) on UNIX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also see my WUSS presentation:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-User-Groups-Library/WUSS-Presentation-Talking-to-Your-Host/ta-p/838344" target="_blank" rel="noopener"&gt;Talking to Your Host&lt;/A&gt;&amp;nbsp;for useful coding tips with regard to file information.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jul 2025 09:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970774#M377153</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-07-15T09:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Files Presence and Details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970775#M377154</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466540"&gt;@Aashi07&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I am using Unix&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is not a problem as all functions used in my suggested code are available in Unix SAS, too. Of course, the path will contain forward slashes instead of backslashes and the "last modified" datetime format may be different. In a preliminary step, you could read that datetime into a &lt;EM&gt;character variable&amp;nbsp;&amp;nbsp;&lt;/EM&gt;like this&lt;/P&gt;
&lt;PRE&gt;lastmod=finfo(fid,'Last Modified');&lt;/PRE&gt;
&lt;P&gt;and then look at the character values in variable LASTMOD to find out the appropriate date or datetime informat to be used eventually.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See also &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0cpuq4ew0dxipn1vtravlludjm7.htm#p05rqdjv55o7vkn1bofnlse4vp9n" target="_blank" rel="noopener"&gt;Example 4 of the FINFO function documentation&lt;/A&gt; where the last modification datetime, among other file information items, is retrieved on a Unix system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you encounter difficulties, please provide details such as the complete log of the DATA step that you tried.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jul 2025 09:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970775#M377154</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-07-15T09:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Files Presence and Details</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970778#M377156</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466540"&gt;@Aashi07&lt;/a&gt;&amp;nbsp;, you can use &lt;A href="https://github.com/SASPAC/baseplus/blob/main/baseplus.md#dirsandfiles-macro-6" target="_self"&gt;%dirsAndFiles()&lt;/A&gt; macro from the &lt;A href="https://github.com/SASPAC/baseplus" target="_self"&gt;BasePlus&lt;/A&gt; SAS package. It encapsulates&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;'s great idea from the "Talking to Your Host" article inside a "user friendly" macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Installation (do it only one the first time):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename packages "/path/for/packages"; /* set a directory for packages */

filename SPFinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas";
%include SPFinit; 

%installPackage(SPFinit baseplus) /* install SAS Packages Framework and BasePlu package*/

filename SPFinit clear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Load package (at the beginning of new SAS session):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename packages "/path/for/packages"; /* set a directory for packages */
%include packages (SPFinit.sas); 

%loadPackage(BasePlus)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use of macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%dirsAndFiles(/path/you/wasnt/to/investigate, ODS=work.results, details=1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Datat set&amp;nbsp;&lt;CODE class=" language-sas"&gt;work.results&lt;/CODE&gt; will have the directory information in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to get help information printed in your log, just run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%helpPackage(BasePlus,dirsAndFiles)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jul 2025 10:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Files-Presence-and-Details/m-p/970778#M377156</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-07-15T10:07:25Z</dc:date>
    </item>
  </channel>
</rss>

