<?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 File Modified Date in Bulk Import in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940381#M369113</link>
    <description>&lt;P&gt;I am trying to get the name and modified date of each file when doing a bulk CSV import, but I am only getting the correct date for the first file in the directory.&amp;nbsp; All of the other files are shown to have the same modified date and name as the first file in the directory alphabetically.&amp;nbsp; (I can get the correct file names using the DREAD system function, so I am primarily concerned with the date).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have modified the bulk CSV import from the SAS example code &lt;A title="SAS Bulk CSV" href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0ctmldxf23ixtn1kqsoh5bsgmg8.htm" target="_blank" rel="noopener"&gt;here&lt;/A&gt; to use the FINFO system function to get the file info within the do loop and put the values to the log.&amp;nbsp;&amp;nbsp; I can see in the log that the file ID passed to the FINFO function changes with each file processed, but the output of the FINFO function is the same for each iteration through the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro drive(dir,ext); 

   %local cnt filrf rc did memcnt name fid ModifyDT rc1;
   %let cnt=0;
   %let filrf=mydir;

   %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
   %let did=%sysfunc(dopen(&amp;amp;filrf));


   %if &amp;amp;did ne 0 %then %do;
      %let memcnt=%sysfunc(dnum(&amp;amp;did));
      %do i=1 %to &amp;amp;memcnt;
	  	 
	  	 %let scanfilename=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));	 
         %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);
         %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
            %if %superq(ext) = %superq(name) %then %do;
               %let cnt=%eval(&amp;amp;cnt+1);
               %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));

			   /* File Info */
			   %let scanfilepath = &amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i));
		 	   %let rc1=%qsysfunc(filename(onefile,&amp;amp;scanfilepath)); 
			   %let fid=%qsysfunc(fopen(&amp;amp;onefile)); 
			   %let ModifyDT=%qsysfunc(finfo(&amp;amp;fid,Last Modified));
			   %let File_Name=%qsysfunc(finfo(&amp;amp;fid,Filename));
			   %put NOTE: FID: &amp;amp;fid;
			   %put NOTE: Path: &amp;amp;scanfilepath;
			   %put NOTE: Name: &amp;amp;File_Name;
			   %put NOTE: Date: &amp;amp;ModifyDT;
			   %put NOTE: &amp;amp;rc1;		   
			
            %end;
         %end;
       %end;	
    %end;
   
%else %put &amp;amp;dir cannot be opened.;
  %let rc=%sysfunc(dclose(&amp;amp;did));
%mend drive;

%drive(D:\TestFiles,csv)&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;BR /&gt;From the Log:

File (1).csv
NOTE: FID: 130
NOTE: Path: D:\TestFiles\File (1).csv
NOTE: Name: D:\TestFiles\File (1).csv
NOTE: Date: 14Aug2024:15:50:57
NOTE: 0&lt;BR /&gt;
File (2).csv
NOTE: FID: 131
NOTE: Path: D:\TestFiles\File (2).csv
NOTE: Name: D:\TestFiles\File (1).csv
NOTE: Date: 14Aug2024:15:50:57
NOTE: 20036&lt;BR /&gt;
File (3).csv
NOTE: FID: 132
NOTE: Path: D:\TestFiles\File (3).csv
NOTE: Name: D:\TestFiles\File (1).csv
NOTE: Date: 14Aug2024:15:50:57
NOTE: 20036&lt;BR /&gt;
File (4).csv
NOTE: FID: 133
NOTE: Path: D:\TestFiles\File (4).csv
NOTE: Name: D:\TestFiles\File (1).csv
NOTE: Date: 14Aug2024:15:50:57
NOTE: 20036&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Aug 2024 19:06:59 GMT</pubDate>
    <dc:creator>dmutolo</dc:creator>
    <dc:date>2024-08-21T19:06:59Z</dc:date>
    <item>
      <title>File Modified Date in Bulk Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940381#M369113</link>
      <description>&lt;P&gt;I am trying to get the name and modified date of each file when doing a bulk CSV import, but I am only getting the correct date for the first file in the directory.&amp;nbsp; All of the other files are shown to have the same modified date and name as the first file in the directory alphabetically.&amp;nbsp; (I can get the correct file names using the DREAD system function, so I am primarily concerned with the date).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have modified the bulk CSV import from the SAS example code &lt;A title="SAS Bulk CSV" href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0ctmldxf23ixtn1kqsoh5bsgmg8.htm" target="_blank" rel="noopener"&gt;here&lt;/A&gt; to use the FINFO system function to get the file info within the do loop and put the values to the log.&amp;nbsp;&amp;nbsp; I can see in the log that the file ID passed to the FINFO function changes with each file processed, but the output of the FINFO function is the same for each iteration through the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro drive(dir,ext); 

   %local cnt filrf rc did memcnt name fid ModifyDT rc1;
   %let cnt=0;
   %let filrf=mydir;

   %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
   %let did=%sysfunc(dopen(&amp;amp;filrf));


   %if &amp;amp;did ne 0 %then %do;
      %let memcnt=%sysfunc(dnum(&amp;amp;did));
      %do i=1 %to &amp;amp;memcnt;
	  	 
	  	 %let scanfilename=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));	 
         %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);
         %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
            %if %superq(ext) = %superq(name) %then %do;
               %let cnt=%eval(&amp;amp;cnt+1);
               %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));

			   /* File Info */
			   %let scanfilepath = &amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i));
		 	   %let rc1=%qsysfunc(filename(onefile,&amp;amp;scanfilepath)); 
			   %let fid=%qsysfunc(fopen(&amp;amp;onefile)); 
			   %let ModifyDT=%qsysfunc(finfo(&amp;amp;fid,Last Modified));
			   %let File_Name=%qsysfunc(finfo(&amp;amp;fid,Filename));
			   %put NOTE: FID: &amp;amp;fid;
			   %put NOTE: Path: &amp;amp;scanfilepath;
			   %put NOTE: Name: &amp;amp;File_Name;
			   %put NOTE: Date: &amp;amp;ModifyDT;
			   %put NOTE: &amp;amp;rc1;		   
			
            %end;
         %end;
       %end;	
    %end;
   
%else %put &amp;amp;dir cannot be opened.;
  %let rc=%sysfunc(dclose(&amp;amp;did));
%mend drive;

%drive(D:\TestFiles,csv)&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;BR /&gt;From the Log:

File (1).csv
NOTE: FID: 130
NOTE: Path: D:\TestFiles\File (1).csv
NOTE: Name: D:\TestFiles\File (1).csv
NOTE: Date: 14Aug2024:15:50:57
NOTE: 0&lt;BR /&gt;
File (2).csv
NOTE: FID: 131
NOTE: Path: D:\TestFiles\File (2).csv
NOTE: Name: D:\TestFiles\File (1).csv
NOTE: Date: 14Aug2024:15:50:57
NOTE: 20036&lt;BR /&gt;
File (3).csv
NOTE: FID: 132
NOTE: Path: D:\TestFiles\File (3).csv
NOTE: Name: D:\TestFiles\File (1).csv
NOTE: Date: 14Aug2024:15:50:57
NOTE: 20036&lt;BR /&gt;
File (4).csv
NOTE: FID: 133
NOTE: Path: D:\TestFiles\File (4).csv
NOTE: Name: D:\TestFiles\File (1).csv
NOTE: Date: 14Aug2024:15:50:57
NOTE: 20036&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 19:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940381#M369113</guid>
      <dc:creator>dmutolo</dc:creator>
      <dc:date>2024-08-21T19:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: File Modified Date in Bulk Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940390#M369119</link>
      <description>&lt;P&gt;I think that you need to FCLOSE the file.&lt;/P&gt;
&lt;PRE&gt;%macro drive(dir,ext); 

   %local cnt filrf rc did memcnt name fid ModifyDT rc1;
   %let cnt=0;
   %let filrf=mydir;

   %let rc=%sysfunc(filename(filrf,&amp;amp;dir));
   %let did=%sysfunc(dopen(&amp;amp;filrf));


   %if &amp;amp;did ne 0 %then %do;
      %let memcnt=%sysfunc(dnum(&amp;amp;did));
      %do i=1 %to &amp;amp;memcnt;
	  	 
	  	 %let scanfilename=%qsysfunc(dread(&amp;amp;did,&amp;amp;i));	 
         %let name=%qscan(%qsysfunc(dread(&amp;amp;did,&amp;amp;i)),-1,.);
         %if %qupcase(%qsysfunc(dread(&amp;amp;did,&amp;amp;i))) ne %qupcase(&amp;amp;name) %then %do;
            %if %superq(ext) = %superq(name) %then %do;
               %let cnt=%eval(&amp;amp;cnt+1);
               %put %qsysfunc(dread(&amp;amp;did,&amp;amp;i));

			   /* File Info */
			   %let scanfilepath = &amp;amp;dir\%qsysfunc(dread(&amp;amp;did,&amp;amp;i));
		 	   %let rc1=%qsysfunc(filename(onefile,&amp;amp;scanfilepath)); 
			   %let fid=%qsysfunc(fopen(&amp;amp;onefile)); 
			   %let ModifyDT=%qsysfunc(finfo(&amp;amp;fid,Last Modified));
			   %let File_Name=%qsysfunc(finfo(&amp;amp;fid,Filename));
			   %put NOTE: FID: &amp;amp;fid;
			   %put NOTE: Path: &amp;amp;scanfilepath;
			   %put NOTE: Name: &amp;amp;File_Name;
			   %put NOTE: Date: &amp;amp;ModifyDT;
			   %put NOTE: &amp;amp;rc1;		   
			   
            %end;
            %let rc2=%sysfunc(fclose(&amp;amp;fid.));
         %end;
       %end;	
    %end;
   
%else %put &amp;amp;dir cannot be opened.;
  %let rc=%sysfunc(dclose(&amp;amp;did));
%mend drive;
&lt;/PRE&gt;
&lt;P&gt;Which does report different dates on one of my folders full of CSV files.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 20:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940390#M369119</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-21T20:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: File Modified Date in Bulk Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940396#M369122</link>
      <description>&lt;P&gt;That did the trick.&amp;nbsp; Much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 20:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940396#M369122</guid>
      <dc:creator>dmutolo</dc:creator>
      <dc:date>2024-08-21T20:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: File Modified Date in Bulk Import</title>
      <link>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940445#M369136</link>
      <description>&lt;P&gt;Make it a habit to always "clean up" after your code. So if you use FOPEN, also use FCLOSE if FOPEN returned a non-zero value.&lt;/P&gt;
&lt;P&gt;Particularly when using FOPEN in macro code, the file handles will pile up, and with a large number of files you can easily exceed the OS limit for open handles per process.&lt;/P&gt;
&lt;P&gt;When using FOPEN in a DATA step, the handles will be automatically closed when the step terminates, but you might still run out of resources within the step.&lt;/P&gt;
&lt;P&gt;The same is true, of course, for OPEN and DOPEN, and other similar stuff.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 10:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/File-Modified-Date-in-Bulk-Import/m-p/940445#M369136</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-22T10:36:49Z</dc:date>
    </item>
  </channel>
</rss>

