<?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: get file modified time and file size in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-file-modified-time-and-file-size/m-p/490704#M128456</link>
    <description>&lt;P&gt;1. Use {i} to post code&lt;/P&gt;
&lt;P&gt;2. Does this work better?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getfilesizes(directory, extension, dataset) ;
  data &amp;amp;dataset. ;
    length FILE $256 DTE 8 SIZE 8 DIRECTORY $256 FILRF FILRFB $8 ;
    format DTE datetime.;
    keep FILE DTE SIZE DIRECTORY ;
    DIRECTORY= "&amp;amp;directory";
    RC1      = filename(FILRF,DIRECTORY);
    DID      = dopen(FILRF);
    MEMCOUNT = dnum(DID);
    do I=1 to MEMCOUNT;
      FILE = dread(DID,I);
      if "&amp;amp;extension" = scan(FILE,-1,'.') or "&amp;amp;extension" = "all" then do;
        RC2 =filename(FILRFB, catx('/', DIRECTORY, FILE) );
        FID =fopen(FILRFB);
        if FID then do;
          DTE =input(finfo(FID,'Last Modified'),anydtdtm.);  
          SIZE=input(finfo(FID,'File Size (bytes)'),32.);
        end;
        else call missing(DTE,SIZE);
        output;
        RC3 =fclose(FID);
        RC4 =filename(FILRFB);
      end;
    end;
    RC5=dclose(DID); RC6=filename(FILRF);
  run;
%mend getfilesizes;

%getfilesizes(directory=%sysfunc(pathname(WORK)), extension=all, dataset=XXX)

proc print width=min;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Aug 2018 03:17:46 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-08-29T03:17:46Z</dc:date>
    <item>
      <title>get file modified time and file size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-file-modified-time-and-file-size/m-p/490692#M128448</link>
      <description>&lt;P&gt;below code (TOM'S) run very well on a computer. While on my computer&amp;nbsp;&lt;SPAN&gt;isize' and 'dte' columns returns blanks.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Anyone can help me?&amp;nbsp; Thank you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro getfilesizes(directory,extension,dataset) ;&lt;/P&gt;&lt;P&gt;data &amp;amp;dataSet ;&lt;/P&gt;&lt;P&gt;length file $256 dte 8 size 8 directory $256;&lt;/P&gt;&lt;P&gt;format dte datetime.;&lt;/P&gt;&lt;P&gt;keep file dte size directory ;&lt;/P&gt;&lt;P&gt;length filrf filrfb $8 ;&lt;/P&gt;&lt;P&gt;directory="&amp;amp;directory";&lt;/P&gt;&lt;P&gt;rc1=filename(filrf,directory);&lt;/P&gt;&lt;P&gt;did=dopen(filrf);&lt;/P&gt;&lt;P&gt;memcount=dnum(did);&lt;/P&gt;&lt;P&gt;do i=1 to memcount;&lt;/P&gt;&lt;P&gt;file = dread(did,i);&lt;/P&gt;&lt;P&gt;if scan(file,-1,'.') = "&amp;amp;extension" or "&amp;amp;extension" = "all" then do;&lt;/P&gt;&lt;P&gt;rc2=filename(filrfb,catx('/',directory,file));&lt;/P&gt;&lt;P&gt;fid=fopen(filrfb);&lt;/P&gt;&lt;P&gt;dte=input(finfo(fid,'Last Modified'),datetime.);&lt;/P&gt;&lt;P&gt;size=input(finfo(fid,'File Size (bytes)'),32.);&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;rc3=fclose(fid);&lt;/P&gt;&lt;P&gt;rc4=filename(filrfb);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;rc5=dclose(did);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend getfilesizes;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%getfilesizes(directory=D:\SASworkdata\workdata,extension=all,dataset=xxx)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc print width=min;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 01:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-file-modified-time-and-file-size/m-p/490692#M128448</guid>
      <dc:creator>derekx</dc:creator>
      <dc:date>2018-08-29T01:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: get file modified time and file size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-file-modified-time-and-file-size/m-p/490704#M128456</link>
      <description>&lt;P&gt;1. Use {i} to post code&lt;/P&gt;
&lt;P&gt;2. Does this work better?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getfilesizes(directory, extension, dataset) ;
  data &amp;amp;dataset. ;
    length FILE $256 DTE 8 SIZE 8 DIRECTORY $256 FILRF FILRFB $8 ;
    format DTE datetime.;
    keep FILE DTE SIZE DIRECTORY ;
    DIRECTORY= "&amp;amp;directory";
    RC1      = filename(FILRF,DIRECTORY);
    DID      = dopen(FILRF);
    MEMCOUNT = dnum(DID);
    do I=1 to MEMCOUNT;
      FILE = dread(DID,I);
      if "&amp;amp;extension" = scan(FILE,-1,'.') or "&amp;amp;extension" = "all" then do;
        RC2 =filename(FILRFB, catx('/', DIRECTORY, FILE) );
        FID =fopen(FILRFB);
        if FID then do;
          DTE =input(finfo(FID,'Last Modified'),anydtdtm.);  
          SIZE=input(finfo(FID,'File Size (bytes)'),32.);
        end;
        else call missing(DTE,SIZE);
        output;
        RC3 =fclose(FID);
        RC4 =filename(FILRFB);
      end;
    end;
    RC5=dclose(DID); RC6=filename(FILRF);
  run;
%mend getfilesizes;

%getfilesizes(directory=%sysfunc(pathname(WORK)), extension=all, dataset=XXX)

proc print width=min;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 03:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-file-modified-time-and-file-size/m-p/490704#M128456</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-29T03:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: get file modified time and file size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-file-modified-time-and-file-size/m-p/490707#M128459</link>
      <description>&lt;P&gt;Also add FID in the kept variables.&lt;/P&gt;
&lt;P&gt;If FID=0 then you are not allowed to open the files, so can't read the date and size with this method.&lt;/P&gt;
&lt;P&gt;There are other methods available if you have access to the system prompt.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 03:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-file-modified-time-and-file-size/m-p/490707#M128459</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-29T03:14:55Z</dc:date>
    </item>
  </channel>
</rss>

